Math Logic Truth Table Generator

Input ; Page open: ; update 2013-11-17
logicmr2.htm Truth Table Generator written by Professor Michael Rieppel.
logictt2.htm default output T/F for math major, logictt2.htm has document.
logictt4.htm default output 0/1 for electronic major, it has NO document.
Michael Rieppel code logicmr2.htm do not accept ambiguous (~A&~Pv~Q)
which can be ((~A&~P)v~Q) f,t,f,t,f,t,t,t or (~A&(~Pv~Q)) f,f,f,f,f,t,t,t
Liu,Hsinhan code logictt2.htm accept ambiguous (~A∧~P∨~Q) and code
convert to ((~A∧~P)∨~Q). If you mean (~A∧(~P∨~Q)) input this way.
Rieppel output exact what you intend. LiuHH output may surprise you.
logictt2, logictt4, logicmr2 output html table code for you to use.
This file is
input box   document  

Programming environment:Window 7; //
MSIE 9.0.8112.16421; Acer Aspire 5750Z-4830
Output to
Text output ; Click [op] Box02 show operators you can use.
Auto group is not reliable, try [33], add () make your intention clear.
Box01, input , ; ; ~ ∨ ∧ → ↔ | ⊽ ⊻

Last line answer ,
Example: ; ; ; la:
Box02, output Bx2 height a64 docC ; HTML ans

box04/05 height and width: a56, a70  
Box04, output 1/2,1/3 ,
Box05, output 2/2,2/3
Box03, HTML table code, paste to your web page.
Box03 code maybe error, please verify with logicmr2.htm ; local

My equation look right, why it does not work? ans.   Display Box03 HTML code
Box06 , symbolic equation history ;

; ; ; ;
Box07 , line answer ; H/W:

Box08 debug ; ; ; goto Bx1

¬~! ∨#+⊕⊻$∧&*•|↑⊼↓⊽ →⇒↔⇔=←⇐ 乙人丩力匕卜厂又
whylist js fail, QiftP, logictt2_va2, re-appear, five degree,
parenthesis pair
onePP=oneLine Parenthesis Pair result

<a name="htmlshow"> Display Box03 HTML code truth table. //a211150749
Next is sample output. Find HTML code for YOUR web page at box03 .
; ; ; goto input box

<a name="docA001">
2021-12-08-21-14 start 
This file 
build logic truth table for you.
Elementary variables accept 
Only uppercase one byte.

<a name="docA002">
Program defined the following Logic functions.

the denial of P (ACaRA01.pdf)
P=true ,	false
P=false,	true

The denial of P operate on one variable.
Following other operator all operate 
on two variables.

<a name="docA003">
inclusive or 
P=true ,Q=true ,	true
P=true ,Q=false,	true
P=false,Q=true ,	true
P=false,Q=false,	false

<a name="docA004">
exclusive or 
P=true ,Q=true ,	false
P=true ,Q=false,	true
P=false,Q=true ,	true
P=false,Q=false,	false

<a name="docA005">
logical connective (ACaRA01.pdf)
P=true ,Q=true ,	true
P=true ,Q=false,	false
P=false,Q=true ,	false
P=false,Q=false,	false

<a name="docA006">
if P then Q 
P=true ,Q=true ,	true
P=true ,Q=false,	false
P=false,Q=true ,	true
P=false,Q=false,	true

<a name="docA007">
P if and only if Q 
P=true ,Q=true ,	true
P=true ,Q=false,	false
P=false,Q=true ,	false
P=false,Q=false,	true

<a name="docA008">
P dull Q, any P,Q always true, dull.
//only logictt2.htm use this operator! 
P=true ,Q=true ,	true
P=true ,Q=false,	true
P=false,Q=true ,	true
P=false,Q=false,	true

<a name="docA009">
P null Q, any P,Q always false, null.
//only logictt2.htm use this operator! 
P=true ,Q=true ,	false
P=true ,Q=false,	false
P=false,Q=true ,	false
P=false,Q=false,	false

<a name="docA010">
PfulQ is "if Q then P". ful follow dul.
P=true ,Q=true ,	true
P=true ,Q=false,	true
P=false,Q=true ,	false
P=false,Q=false,	true

<a name="docA010b">
PvulQ is Sheffer Stroke. wikipedia 
P|Q=P↑Q=PvulQ(P,Q)  //a112312121
PvulQ(P,Q)=P nand Q //a201061512
P=true ,Q=true ,	false
P=true ,Q=false,	true
P=false,Q=true ,	true
P=false,Q=false,	true

<a name="docA010c">
PpulQ is vice-Sheffer Stroke. 
//only logictt2.htm use this term! 
P⊽Q=P↓Q=PpulQ(P,Q)  //a112312146
PpulQ(P,Q)=P nor Q  //a201061513
P=true ,Q=true ,	false
P=true ,Q=false,	false
P=false,Q=true ,	false
P=false,Q=false,	true 

<a name="docA010d">
P人Q=PgulQ(P,Q) always=P  //a201061520
//only logictt2.htm use this operator! 
P=true ,Q=true ,	true
P=true ,Q=false,	true
P=false,Q=true ,	false
P=false,Q=false,	false

<a name="docA010e">
P丩Q=PhulQ(P,Q) always=Q  //a201061525
//only logictt2.htm use this operator! 
P=true ,Q=true ,	true
P=true ,Q=false,	false
P=false,Q=true ,	true
P=false,Q=false,	false

<a name="docA010f">
P力Q=PtulQ(P,Q) always=~Q //a201061527
//only logictt2.htm use this operator! 
P=true ,Q=true ,	false
P=true ,Q=false,	true
P=false,Q=true ,	false
P=false,Q=false,	true

<a name="docA010g">
P匕Q=PsulQ(P,Q) always=~(P→Q) //a201061529
//only logictt2.htm use this operator! 
P=true ,Q=true ,	false
P=true ,Q=false,	true
P=false,Q=true ,	false
P=false,Q=false,	false

<a name="docA010h">
P卜Q=PrulQ(P,Q) always=~P //a201061532
//only logictt2.htm use this operator! 
P=true ,Q=true ,	false
P=true ,Q=false,	false
P=false,Q=true ,	true 
P=false,Q=false,	true 

<a name="docA010i">
P厂Q=PqulQ(P,Q) always=~(P←Q) //a201061533
//only logictt2.htm use this operator! 
P=true ,Q=true ,	false
P=true ,Q=false,	false
P=false,Q=true ,	true 
P=false,Q=false,	false

<a name="docA011">
PiftQ(P,Q) is "IF P Then Q" 
PiffQ(P,Q) is "P IF and only iF Q"
Above two lines uppercase in "quoted" 
string is part of function name.

PfulQ(P,Q) is Q→P written in P←Q.
If you see P→Q use PiftQ(P,Q)
If you see P←Q use PfulQ(P,Q) or PiftQ(Q,P)

<a name="docA012">
Logic equation (P→Q)↔((P)∨(~Q)) 
must enter as 
Above 'must' is first version 
requirement. Later updated version 
accept symbolic equation. a112231645

<a name="docA013">
Today 2012-12-08 upload logictt2.htm 
it is copied from draft 
[logictt2_v08 begin sym2fun1() ]
Draft continue to 
But logictt2_v22 javascript stop work.

<a name="docA014"><a name="a112082020why">
Even next simple code stop respond. 
function  sym2fun1(arg1) 
return 'a112082020'; 

<a name="docA015">
sym2fun1() final version will change 

Now 2012-12-08 middle way, 
sym2fun1() change 
success. Need final assembly.

<a name="docA016">
When work at next example equation 
javascript stop work.
If later, LiuHH re-gain javascript 
function. LiuHH will continue write 
symbol equation 
function equation.

<a name="docA017">
Please visit
Math Logic study notes 2012-11-30 
2012-12-08-21-40 stop

<a name="docA018">
function  sym2fun1(arg1) 
return 'a112082020'; 
begin work

<a name="docA019">
2012-12-13-12-05 record
Now need to write code follow 
Order of Operation for Logical Operators.
Earlier study notes is next.

<a name="docA020">
2012-11-17-12-54 open
1.4.6. Order of Operation for Logical Operators.
The order of operation for logical 
operators is as follows:

<a name="docA021">
1. Evaluate negations first

2. Evaluate ∨ and ∧ second. When both 
are present, parenthesis may be needed, 
otherwise work left to right.

3. Evaluate ⇒ and ⇔ third. When both 
are present, parenthesis may be needed, 
otherwise work left to right.

<a name="docA022">
Note: Use of parenthesis will determine 
order of operations which over ride the 
above order.

Indicate the order of operations in the 
<a name="docA023">



<a name="docA024">
︸ ︸ 
1 2 
︸ ︸  ︸ 
1 3  2 
Number 1,2,3 indicate evaluation order.
︸  ︸  
2  1  
︸ ︸ ︸ 
1 3 2 
<a name="docA025"> a112201033 Alert! above equation do not work in logictt2.htm Because "~", "(", ")" are Unicode. They are not "~", "(", ")" Ascii code. Second, Unicode "p,q,r" are not accepted. Ascii uppercase "P,Q,R" needed. Change above to "~P∧(Q∨R)" for logictt2.htm requirement. a112201040 //2St Paste " ~p∧(q∨r) " to box01, first click second click to get answer. a201061617 <a name="docA026"> Exercises: Indicate the order of operations in the following:
 ︸ ︸  ︸ 
 1 2  3 
︸ ︸ ︸ 
1 3 2 
<a name="docA027">
︸  ︸  
2  1  
︸ ︸ ︸ 
1 3 2 
]] above copied from LogicTeacher.pdf 2012-11-17-13-23 notes stop 2012-12-13-12-09 record stop <a name="docA028"> 2012-12-18-17-47 start update 2012-12-20 is a major change. update 2012-12-20 allow user input symbolic logic equation to box01 click get html code output at box03. There are two click buttons and "run code eq." not exist now, it change to better "run two eq." change date 2012-12-22-12-39 All [run] click button simplified to one click button. 2013-01-06-16-25 <a name="docA029"> require input code equation to Box01, and it must be first line. require input symbol equation to Box01, and it can be any line. But first line contain "~ ∨⊻∧ →←↔ ⇐⇒⇔" symbol equation example A∧B code equation example PandQ(A,B) code equation = function equation. Both "PandQ(A,B)" and "A∧B" are ONE THING. <a name="docA030"> Symbol equation is easier for user. Code equation need some user twist. Code equation is easier for programmer. It is heavy code work to convert symbol equation to code equation. Conversion is necessary, because function eval() read only code equation. //Professor Michael Rieppel code //logicmr2.htm do NOT use eval(). //see j.s. bible a201061628 <a name="docA031"> Version "upload 2012-12-08" accept only code equation, it is hard for user. Version "update 2012-12-20" accept both code equation and symbol equation. Although Liu,Hsinhan tried his best to get conversion correct, but there is no promiss !! Conversion may contain error !! You MUST verify first. check with <a name="docA032"> Output box has two different version. If you input only code equation at Box01 line one. Not input symbol equation. Click either or program output text answer to Box02 and output html code answer to Box03. <a name="docA033"> If you input only symbol equation at Box01 line one. Not input code equation. Click get error message. Click program output text answer to Box02 and output html code answer to Box03. Output symbol to code conversion history to Box06. Above input only one type equation. <a name="docA034"> Below input two types equation. If input code equation at Box01 line one, input symbol equation at Box01 line two. Click get answer at Box02/Box03. Click program output text answer to Box04 and Box05 side by side, let user compare. (main purpose is debug code) <a name="docA035"> Box04 from Box01 line two symbol equation. Box05 from Box01 line one code equation. Box04 marked "logic1Line(sym2fun1(box01))" sym2fun1() is symbol to function function equation = code equation. Box05 marked "logic1Line(box01)" Box05 not involve sym2fun1() <a name="docA036"> Output to Box04 and Box05 side by side, the purpose is to verify sym2fun1() do job right or not. Output to Box04 and Box05 side by side, Box02 record Box01 line two symbol equation parenthesis pair scale result. Box03 record Box01 line two symbol equation html table code. <a name="docA037"> Usually, input code eqn. at Box01 line one, input symbol eq. at Box01 line two for same equation, so that compare Box04 and Box05 is possible. For example, next two lines PiorQ(P,Q) P∨Q are same equation. <a name="docA038"> UN-usually, input code eqn. at Box01 line1, input symbol eq. at Box01 line2 for two DIFFERENT equation, so that it is easy to see Box02 and Box03 serve code eqn? or serve symbol eq. For example, next two lines PiorQ(P,Q) ~Q are different equations. <a name="docA039"> Text output narrow let user control the form of text output. wider output is "P=true ,Q=true , true" narrow output is "Pt, Qt, true" Right most "true" is logic expression evaluation based on "true" left values. <a name="docA040"> For example equation P∧Q when P=true ,Q=true , true (P∧Q=true) or narrow, when Pt, Qf, false (P∧Q=F) Pt is short write for P=true Qf is short write for Q=false . If you want P,Q on column top and not want "P=true ,Q=true", not want "Pt, Qf", please copy Box03 html table code. Here is one example output <a name="docA041"> Logic equation is a combination of elementary logic variable. For example P,Q,R etc. Elementary logic variables must be Boolean type. It has only true or false two possible values. <a name="docA042"> Program limitation logictt2.htm building block is Boolean type elementary logic variable. logictt2.htm do not accept expression like P=(3>5) which is false, nor Q=(2,4,6 are even) which is true. These evaluation must be done by human brain before start logictt2.htm . <a name="docA043"> It is very hard for electronic brain to evaluate infinite many true/false decision. God build human brain, human brain build electronic brain, electronic brain build logic truth table, and logic truth table build my confidence. How lucky I am! Oh! Dear GOD thank you! <a name="docA044"> logictt2.htm accept 26 elementary logic variables. They are all uppercase English alphabet. Uppercase T is logic variable, T can be false or true. Uppercase F is logic variable, F can be true or false. User may choose not to use T,F as variables. 2012-12-18-19-32 stop <a name="docA045"> 2012-12-19-10-23 start Elementary logic variables are A,B,C,D,E,F,G,H,I,J,K,L,M, N,O,P,Q,R,S,T,U,V,W,X,Y,Z Logic operators are ¬,~,∨,⊻,∧,→,←,↔,⇒,⇐,⇔ <a name="docA046"> Important logic operators are ~,∨,∧,→,↔ They correspond to logic function as following (A,B are logic variables) ~ relate to notP(A) definition ∨ relate to PiorQ(A,B) definition ∧ relate to PandQ(A,B) definition → relate to PiftQ(A,B) definition ↔ relate to PiffQ(A,B) definition Logic Binary Total Table, study notes. <a name="docA047"> Operator '¬' is same as '~', program replace all '¬' with '~'. Operator '⇒' is same as '→', both '⇒' and '→' change to PiftQ(*,$) Both be "if A then B" <a name="docA048"> Operator '⇔' is same as '↔', both '⇔' and '↔' change to PiffQ(*,$) Both be "A if and only if B" Operator '⇐' and '←' are reverse operation of PiftQ(*,$). 'A←B' is "if B then A" <a name="docA049"> Operator '⇐' and '←' both change to PfulQ(*,$) which is reverse of PiftQ($,*) Please visit Math Logic study notes 2012-11-30 2012-12-19-10-46 stop <a name="docA050"><a name="QiftP{B,A}_why"> 2012-12-19-10-47 input (A→B) ↔ (B←A) get QiftP{B,A} ??!! 2012-12-19-11-02 in logictt2.htm change 'QiftP' to 'PfulQ' save as logictt2_v59_delete_QiftP.htm <a name="docA051"> 2012-12-19-11-28 start Between box01 and Box02 there is an example box for number 1-56. (later extend to 0-60) They come from and Liu,Hsinhan made examples 32 to 40 to test code. 0 and 60 are Sheffer Stroke and its original form. <a name="docA052"> Example "36" is ERROR on purpose (P∨Q)→R)))↔((((P→R)∧(Q→R) ')))↔(((' is wrong. //a112101809 Code must be able to detect error, otherwise "36" get infinite loop. Example "50", "51" has answer different from logicTeacher.pdf Need reader judge. //a201201356 purple Example 36 second (A∨B)→(C↔D)∧(E∨G) done level 0 get (lvl0)→(lvl0)∧(lvl0) level 1 has both → and ∧ they have different priority. Add '()' make your intention clear. <a name="docA053"> When click example button, if see first line be code equation PiffQ(A,B) and second line be symbol eq. A↔B you can click /*deleted*/ or click to get answer. ignore symbol equation. care both code eq. and symbol equation. Because earlier version program accept only code eq. Newer ver. program accept both. All [run] click button simplified to one click button. 2013-01-06-16-50 <a name="docA054"> There are 56 example buttons, which one I just clicked? Sometime forget (LiuHH is 65 years old) Box03, table code line right side has "data from:03" It remind user which example button just clicked. If user modify Box01, "data from:user" printed. //a112231156 to gray <a name="docA055"> Example "31" is (A→(B∨C))↔((S→T)∨(U→V)) It has seven elementary logic variables. "31" test program's capability to build logic variables array correctly [[ At, Bt, Ct, St, Tt, Ut, Vt, true At, Bt, Ct, St, Tt, Ut, Vf, true ..... At, Bf, Cf, Sf, Tf, Ut, Vt, false At, Bf, Cf, Sf, Tf, Ut, Vf, false ..... Af, Bf, Cf, Sf, Tf, Uf, Vt, true Af, Bf, Cf, Sf, Tf, Uf, Vf, true ]] <a name="docA056"> seven variables build 2^7=128 output lines. Box04/05 has only 10 lines height. Program let user to change Box04/05 height setting. At [[ box04/05 height and width: [ 10,36 ] Box04, output 1/2,1/3 ]] <a name="docA057"> change "10,36" to larger number, then Box04/05 height/width will expand. Click return to 10 lines height. Box width can not change, because many elementary logic variables equation is rare. LiuHH did not write width control code. update 2012-12-22 relaxed However, Box03 output has table width control code, no need height control code. Table has 100% height. See sample table. 2012-12-19-12-06 stop <a name="docA058"> 2012-12-19-20-43 start If I have a symbolic equation in hand, how to get its equivalent code equation? It is easy, put symbolic equation to Box01, click , Box02 last line is equivalent code equation. Box06 last line is also equivalent code equation. <a name="docA059"> Next question. If I have a code equation in hand, how to get its equivalent symbolic equation? It is no way, logictt2.htm do not have such conversion function. You can do it by hand. For example, easy one given PandQ(P,Q), hand change to ∧(P,Q), then hand change to P∧Q . Done <a name="docA060"> For example, simple twist (example 13) given PiorQ(PiftQ(P,R),PiftQ(Q,R)) hand change to ∨(PiftQ(P,R),PiftQ(Q,R)) hand change to PiftQ(P,R)∨PiftQ(Q,R) hand change to [→(P,R)]∨[→(Q,R)] hand change to [(P→R)]∨[(Q→R)] hand change to (P→R) ∨ (Q→R) done. Complicate twist follow same pattern. 2012-12-19-21-00 stop <a name="docA061"> 2012-12-19-21-56 start To quote an expression, you can use (A∧B) or {A∧B} or [A∧B] or <A∧B>. Program will convert "{}", "[]", "<>" to "()". Expanded quotation allow user see matching pair easier. For example example 37 equation is //next line eq.37a [{ ~A∧~P∨~Q→~R ∨ B∧C}↔(P→ <Q∨R> ∧ <Q∨A> )] [37] has all "{}", "[]", "<>", "()" example 37 still output correct answer. (LiuHH hope so, did not verify. verified) 2012-12-19-22-05 here <a name="docA062"> You can input equation without any one of "{}", "[]", "<>", "()". example 38 equation is ~A∧~B∨~C→~D∨E∧F↔G∨~H∧I ---eq.38a Since parenthesis is vital in symbol to code equation conversion analysis, logictt2.htm auto insert "(", ")" to get (~A∧~B∨~C→~D∨E∧F↔G∨~H∧I) then continue analysis. Without "(", ")" program can not find level 0 string. In example 38 case level 0 string is "~A∧~B∨~C→~D∨E∧F↔G∨~H∧I" 2012-12-19-22-16 stop <a name="docA063"> 2012-12-22-17-42 start update 2012-12-22 made three relax. 1. button convert Box01 data to logictt2.htm standard. 2. button read top two lines equation. 3. box04/05 height and width box read height and width values. <a name="docA064"> Explain as following. 1. button convert Box01 data to logictt2.htm standard. Earlier alert suggest reader Change from "~p∧(q∨r)" to "~P∧(Q∨R)" for logictt2.htm requirement. Now this change can be done by one click at button. This button change Unicode upper/lowercase alphabet to Ascii uppercase alphabet, and change isolated Ascii lowercase alphabet to Ascii uppercase alphabet. <a name="docA065"> For example change from "~P∧(Q∨r) a formula i entered" to "~P∧(Q∨R) A formula I entered" "(Q∨R)" is necessary for logictt2.htm button also change some of logic pdf file used string. For example from '_' to '∨' used in chapter01.pdf from '^' to '∧' used in chapter01.pdf <a name="docA066"> from '®' to '→' used in Logic_Notes01.pdf from '«' to '↔' used in Logic_Notes01.pdf etc. Logic pdf file string replacement is not complete. User MUST verify the result of replacement. 2012-12-22-18-12 here <a name="docA067"> 2. button read top two lines equation. Liu,Hsinhan provide Box04/05 initial goal is for debug purpose. Box01 line one code equation must be same as line two symbol equation. Later (2012-12-20/21) found that Box04/05 two boxes output is useful. <a name="docA068"> They let user compare two expressions, see their identity or see difference. For this purpose, it is better let user input two symbol equations, instead of input one code equation, one symbol equation. Early version is broader than and is redundant. Now change to . read line one and line two two equations. All [run] click button simplified to one click button. 2013-01-06-18-16 //If input one equation, click <a name="docA069"> They can be both symbol equation, or both code eqn. or mixed. build text output to Box04/05 replace table top code equation with user equation. build html output to Box03 replace table top code equation with user equation. Example 38 fit OK. 2012-12-22-18-29 here <a name="docA070"> 3. box04/05 height and width box read height and width values. Earlier version input box care only height. Run example 38, box 04/05 width is too short. Now modify code, let box contain two numbers, separated by ',' or ' '. First number is height, second is width. One number is height. Height > 10 has action. Width > 36 has action. Example 38 test box04/05 height and width box. <a name="docA071"> Above changes let user work easier. But change a code equation to equivalent symbolic equation still no way. It has much code work to do and very little chance to use this conversion function. 2012-12-22-18-40 stop <a name="docA072"> 2012-12-23-15-22 start update 2012-12-23 main change is 1. bring input box, output box closer. 2. add button for three equations. <a name="docA073"> To bring input box, output box closer, first thing to do is move Box03 from above Box04/05 to below. Second thing to do is delete all example buttons. Now, example can be accessed by filling number 0-60 in example box below Box01. <a name="docA074"> To bring input box, output box closer, third thing to do is to minimize Box02. If click , output to Box04/05. then Box02 is in between in/out boxes. update 2012-12-23 add Box02 height control function Box02 height: Click "1" Box02 height is one line, which is minimized, bring input Box01, output Box04/05 closer. <a name="docA075"> If click , output to Box02. Click "6" Box02 height is six lines, good for P,Q two variables. 2^2=4 lines plus equation two lines, 4+2=6 lines. Click "10" Box02 height is ten lines, good for P,Q,R three variables. 2^3=8 lines plus equation two lines, 8+2=10 lines. Click "18" Box02 height is 18 lines, good for P,Q,R,S four variables. 2^4=16 lines plus equation two lines, 16+2=18 lines. Other number height is accepted. <a name="docA076"> Second change 2. add button for three equations. Choose example 11, fill three equations to input Box01, click program output line one to Box04, output line two to Box05, output line three to Box02. Main output is Box03 html table code. Copy Box03 value and paste to one html file, save file, refresh page to see three tables side by side. Sample output is here update 2012-12-23 also update tute0056.htm and parenpr2.htm. In these files add link to logictt2.htm. 2012-12-23-15-56 stop <a name="docA077"> 2012-12-31-15-51 start update 2012-12-31 change at time stamp a112242357 and a112242359 allow Window8 input boxes work properly. <a name="docA078"> logictt2.htm programming environment is Window 7 and MSIE 9.0.8112.16421; Acer Aspire 5750Z-4830 Liu,Hsinhan did not know Window8 cause trouble. <a name="docA079"> 2012-12-24-10-35 Liu,Hsinhan and sister went to brother house (see here) Brother has a Window8 HP-Compaq computer. LiuHH test run logictt2.htm on Window8 found that code arr8=boxc01.value.split('\r\n'); is invalid in Win8 (OK in Win7) 2012-12-30-17-01 Liu,Hsinhan back to his room at Simi Valley. <a name="docA080"> 2012-12-24-23-5? change to next code [[ if(boxc01.value.indexOf('\r\n')>=0) //a112242359 arr8=boxc01.value.split('\r\n'); //add if()else else if(boxc01.value.indexOf('\n')>=0) arr8=boxc01.value.split('\n'); else arr8=boxc01.value.split('\r');//for window8 ]] program work in Window8 computer. <a name="docA081"> Brother has faster Internet connection, 2012-12-24-20-11 Liu,Hsinhan access save as www.ocf.berkeley.edu_~mrieppel_prog_truthtable.html 2012-12-28-16-47 Liu,Hsinhan access save as logicttg_mrieppel_sheffer.html <a name="docA082"> mrieppel_prog_truthtable.html run better than logictt2.htm Now Liu,Hsinhan upload to internet, which is a mirror page of truthtable.html and logicmr2.htm have identical code. The difference is that truthtable.html do not give HTML table code, reader can only see the result. <a name="docA083"> On the other hand, logicmr2.htm has same answer as truthtable.html, logicmr2.htm has box01 and box02 store HTML table code let reader copy paste to reader's own page. Be able to copy HTML code is advantage to reader. But output to box01/02, let logicmr2.htm run slower than truthtable.html <a name="docA084"> Simple guide line If read output, go to truthtable.html If copy output, go to logicmr2.htm logicmr2.htm is Michael Rieppel code. logictt2.htm is Liu,Hsinhan code. <a name="docA085"> Difference between logicmr2.htm and logictt2.htm is that Michael Rieppel's Truth Table Generator logicmr2.htm run better than Liu,Hsinhan's Truth Table Generator logictt2.htm Liu,Hsinhan always declare that LiuHH is programming admirer and mathematics admirer. LiuHH is happy to present Michael Rieppel code in domain. 2012-12-31-16-23 stop <a name="docA086"> 2013-01-06-09-00 start update 2013-01-06 is a major change. The changes are 1. expand logic operator definition. 2. output T/F or output 0/1 3. add example button , . 4. Run button reduce to one 5. Box03 html code output add date/time stamp. 6. added rare used, not used functions. <a name="docA087"> First change is that program expand logic operator definition to cover some other author's usage. Please see binaryTotal γ δ row. For example not P can be ~P, ¬P, !P . Red ~P is used in logictt2.htm Program convert black ¬P, !P to red ~P. <a name="docA088"> OR operator can be ,#,+. If P then Q can be ,⇒ P if and only if Q can be ,⇔,=. AND operator can be ,&,*,• . NAND operator can be |,↑,⊼, Sheffer Stroke. XOR operator can be ,⊕,$. NOR operator can be ,↓. Not supported operators are, for example, '>' as conditional 'v' as disjunction <a name="docA089"> Because logictt2.htm allow user use '[]', '{}' and '<>' as parenthesis, then '>' has two different roles, '>' is either or '>' is ')'. If user copy equation from logicmr2.htm and paste to logictt2.htm boc01, which contain '>' for example "((P&(Q>R))vS)", user must click first, then click . convert '>' to and convert 'v' to . <a name="docA090"> logictt2.htm not supported operator 'v' as disjunction , because 'v' is an alphabet. If logictt2.htm auto convert 'v' to , then document line below equation line distort from "Above equation has only true value" to "Aboe equation has only true alue" <a name="docA091"> Second change is that program expand output from T/F only to T/F and 0/1. Liu,Hsinhan search online for "logic truth table" find several electronic engineering web page. They use 0/1 for false/true. LiuHH modify program code at time stamp a201041648 a201041705 a201042006 a201042008 a201042022 a201042034 a201042035 a201042050 <a name="docA092"> View logictt2.htm source code, key steps are var T01='=true '; var F01='=false'; //use T/F if(tf10==1) //use 0/1 {T01='=false';F01='=true ';} //a201042006 and <a name="docA093"> if(tf10==1) //output 0/1 //a201042008 m6=m5.replace('=true ','1').replace('=false','0') else //output T/F m6=m5.replace('=true ','T').replace('=false','F') and //above return T/F //below return 0/1 a201042035 <a name="docA094"> Liu,Hsinhan add the following control switch
Output to T/F ; mathematics major use T/F
It is a simple click to flip between 
T/F and 0/1.
logictt2.htm default start up at T/F 
logictt4.htm default start up at 0/1 

<a name="docA095">
logictt2.htm use code 
id="chkbxT12" type="checkbox" 
logictt4.htm use code 
id="chkbxT12" type="checkbox" checked
logictt4.htm let electronic engineer use 
0/1 output directly without worry how to 
modify html code. 
2013-01-06-10-12 stop 

<a name="docA096">
2013-01-06-11-36 start 
logictt2.htm and logictt4.htm code 
difference is only with or without 
checked. LiuHH decide to delete 
most document from logictt4.htm . If 
logictt4.htm user need document, go 
to logictt2.htm find them.

<a name="docA097">
Third change, add example button ,.
update 2013-01-06, example range from 
0 to 60. 0 and 60 are Sheffer Stroke.
Example 37 show that [],{},<> are same 
as (). Click button  and  allow user 
test run example 0 to 60 easier.
2013-01-06-11-52 stop 

<a name="docA098">
2013-01-06-12-12 start 
Fourth change, run button reduce to one 
. Early version has 3 buttons, 
New code run for three equations. If 
hit error, then stop.

<a name="docA099">
Fifth change, Box03 html code output add 
date/time stamp. This function help user
remember when truth table is created. 
logictt2.htm, logictt4.htm, logicmr2.htm 
all added date/time stamp. 
2013-01-06-12-24 stop 

<a name="docA100">
2013-01-06-12-12 start 
Sixth change, program added rare used, 
or not used functions.
P乙Q = PdulQ(P,Q) always true 
P人Q = PgulQ(P,Q) output is same as P 
P丩Q = PhulQ(P,Q) output is same as Q 
P力Q = PtulQ(P,Q) output is same as ~Q 
P匕Q = PsulQ(P,Q) output is same as ~(P→Q) 
P卜Q = PrulQ(P,Q) output is same as ~P
P厂Q = PqulQ(P,Q) output is same as ~(P←Q) 
P又Q = PnulQ(P,Q) always false 

<a name="docA101">
乙人丩力匕卜厂又 are rare used operator. They 
are Chinese character, they do not conflict 
with existing math symbol. 
Please see binaryTotal γ δ row for 
rare used operator 乙人丩力匕卜厂又 , 
each rare used column has function 
output T/F value.

<a name="docA102">
"乙" read yee like alphabet E
"人" read zen like zen in dozen
"丩" read jiu like gee+you
"力" read lee like name Lee
"匕" read bee like bee, be
"卜" read boo like book drop k
"厂" read han like hand drop d
"又" read yiu like you.

<a name="docA103">
"乙" mean second, grade 乙=grade B
"人" mean human. everyday use.
"丩" mean tangling, rare used. 糸 is silk,
    糸+丩=糾=frequent used for tangling. 
"力" mean force. everyday use.
"匕" mean knife. 
"卜" mean to divine, to foretell, to select.
"厂" mean dwell-able hill side cave. rare used.
"又" mean again. everyday use.
2013-01-06-13-26 stop 

<a name="docA103b">
2013-01-15-15-31 start
"summer" is second in an array of four.
"February" is second in an array of twelve.
"乙" is second in an array of ten. 
Everyone say "second opinion", 
no one say "summer opinion"
no one say "February opinion"
no one say "乙 opinion" either.
"second" in "second opinion" Chinese is 第二.
2013-01-15-15-36 stop

<a name="docA104">
2013-01-06-15-52 start  
equation  P v ~Q  and
equation  (Pv~Q)  both work in logicmr2.htm 
equation  P v ~Q  not  work in logictt2.htm
equation  (Pv~Q)  can  work in logictt2.htm

<a name="docA105">
When user click  
"P v ~Q" change to "P V ~Q" it is an error.
"(Pv~Q)" change to "(P∨~Q)" it is right.
"P v " change to uppercase "P V " there is 
no operator between P and V.
"Pv" change to "P∨", "∨" is AND operator.
has space "P v" or no space "Pv" make 

<a name="docA106">
Rare used function/operator 乙人丩力匕卜厂又 
its priority is not defined. They are 
grouped with "→,⇒; ↔,⇔,=" If user need 
try operator 乙人丩力匕卜厂又, please add 
'()' to make your intention clear.
2013-01-06-16-12 stop 

<a name="docA107">
2013-01-06-17-56 start 
2013-01-06-17-18 LiuHH verified 
example 37 equation 
Liu,Hsinhan program: logictt2.htm 
Michael Rieppel code logicmr2.htm 
two output are identical !! 

<a name="docA108">
Michael Rieppel code require user assign 
group clearly ((~A&~P)v~Q) is OK

Michael Rieppel code do not accept 
(~A&~Pv~Q) which can be 
((~A&~P)v~Q) f,t,f,t,f,t,t,t
(~A&(~Pv~Q)) f,f,f,f,f,t,t,t
<a name="docA109">
Liu,Hsinhan code group ~A∧~P∨~Q to 
that is ((~A∧~P)∨~Q) 
Auto group is not reliable, try example  
[33], add () make your intention clear.
2013-01-06-18-01 stop

<a name="docA110">
2013-01-07-17-30 start 
update 2013-01-07 has one change. 
Convert column answer to row answer. So 
that it is possible to compare two by 
program function. Relax user's eye. 

2012-12-19 LiuHH said that hope 
example 37 output right answer.

<a name="docA111">
2012-12-24-20-11 Liu,Hsinhan access

2012-12-31 Liu,Hsinhan's upload 
truthtable.html to 
2013-01-06-17-18 LiuHH verified 
example 37 equation 

<a name="docA112">
Liu,Hsinhan program: logictt2.htm 
Michael Rieppel code logicmr2.htm 
two output are identical. 

<a name="docA113">
2013-01-06-17-18 work compare two table 
two vertical columns. If it were P,Q 
two variable four combination, that is 
easy. Now example 37 has A B C P Q R six 
variables 2^6=64 combination, 64 T/F in 
two tables. Not very easy. 2013-01-07 
Liu,Hsinhan decide write a comparison 
code. To compare two vertical columns 
must let them sleep on floor. First, 
write code change column T/F to row T/F. 
Now in logictt2.htm and logicmr2.htm add
line answer one-line box. In logictt2.htm 
Add Box07. 

<a name="docA114">
If logictt2.htm Box01 has one equation, 
click [run Box01], line answer box record 
answer in row form. Box07 record same thing.

If logictt2.htm Box01 has two equation, 
click [run Box01], line answer box record 
last equation answer in row form. 
Box07 record line1 equation answer, and 
record line2 equation answer. 
Box07 record up to three equation answer.

<a name="docA115">
Above is logictt2.htm T/F answer. 
In logicmr2.htm copy logicmr2.htm line 
answer value, paste to logictt2.htm Box07. 

If logictt2.htm generate T/F output, 
if Box07 has both answer from logictt2.htm 
and from logicmr2.htm, click [T⊥⇒TF] and 
click [compare]. Input at Box07, output to 
[compare] stop work, if Box07 has '=', 
avoid user click [compare] twice.

<a name="docA116">
If logictt2.htm generate 0/1 output, 
if Box07 has both answer from logictt2.htm 
and from logicmr2.htm, click 
[TF⇒10 then reverse] and click [compare], 
logictt2.htm 0/1 output P,Q,R=0,0,0 first.
logictt2.htm T/F output P,Q,R=T,T,T first.
If Box07 has T⊥ answer from logicmr2.htm 
and 0/1 answer from logictt2.htm, two ans. 
are upside down to each other, must click 
[TF⇒10 then reverse] can not click [TF⇒10] 

<a name="docA117">
[compare] program 
compare Box07 line1 with Box07 line2
compare Box07 line2 with Box07 line3 etc.
Example [33] input/output is next 
Above is input, below is comparison. '|' is difference. a201071320

<a name="docA118">
Box07 has height/width control box. It is 
same as box04/05 height and width control 
With this compare utility, compare two 
truth table vertical answer is an easier 
Writing code work hit ceiling, next few 
days, LiuHH will write code document. 
2013-01-07-18-29 stop 

<a name="docA119">
2013-01-16-20-34 start 
On top of Box02, there is a "Example" line. 
Its right end has la:
One line above it has 
line answer [cL] [dL] 
long box. If change la: box value, 
long box length change to new length. 
If input equation has 5 or less variable 
line answer box default length 60 is OK.
If input equation has 6 or more variables,
user change la: box value, let line answer 
box become longer. Any value greater than 
10 has response.
[cL] is copy line answer box value. 
[dL] is delete line answer box value. 
2013-01-16-20-46 stop 

<a name="docA120">
2013-01-20-18-20 start 
update 2013-01-20 added function sym2fun1()
document at docC014.
function logic1Line(arg1) document wait 
for next update.
During debug, at Box01, input line right 
end added "⊆ &#8838;" print. It has 242 
different pattern. Start from &#8704; to 
&#8945;. If click Box08 debug [v] on 
and if run example 38, Box01 right end 
print "add ( ) pair" debug flag.
update 2013-01-20 added Box08 debug. If 
click box on, program run slower, example 
60 is much slower.
2013-01-20-18-35 stop 

<a name="docA121">
2013-01-25-17-31 start 
update 2013-01-25 add document for 
function logic1Line(arg1)
update 2013-01-25 add code 
var eqTF=[]; //equation True/False
for(i0=0;i0<m2.length;i0++) //a201222003
Call eval() just one loop, not two loops.

<a name="docA122">
update 2013-01-25 Re-write updateStr()
Older version updateStr() cause infinite 
loop. New version avoid this trouble.
update 2013-01-25 Add click buttons   
click button  write three lines 
abc1 abc2 abc3
to box07. 
<a name="docA123">
Its meaning is in string "abc1 abc2 abc3"
replace "abc" with "abcYZ". click button  
test new version updateStr(), make sure no 
infinite loop.
Click button  generate random ID string. 
If fill 50 in Box07, click  output 50 bytes 
random ID string to Box08. If Box07 is empty, 
default output 20 bytes to Box08.

<a name="docA124">
update 2013-01-25 in example 0 to 60, add 
logicmr2.htm compatible equations, let user 
compare two programs, make sure one equation 
get identical answer from both logictt2.htm 
and from logicmr2.htm 

<a name="docA125">
To compare, in logictt2.htm click  
program auto send answer to logictt2.htm 
box07. In logicmr2.htm click   
copy logicmr2.htm line answer value. Paste 
answer to logictt2.htm box07. 
click  change logicmr2.htm T⊥ to TF.
click  Box07 show up answer. 
<a name="docA126">
If Box07 compare line all be '=' that is 
identical answer. 
If Box07 compare line has '|', logictt2.htm 
answer and logicmr2.htm answer are different. 
Until now 2013-01-25, Liu,Hsinhan found 
same equation get same answer from both  
logictt2.htm and logicmr2.htm

<a name="docA127">
Next update will be logictt4.htm and 
After next update, Liu,Hsinhan work will 
move to write Chinese program logictt1.htm
logicmr1.htm, tutc0056.htm, parenpr1.htm
2013-01-25-18-19 stop

<a name="docA128">
2013-01-26-14-24 start
update 2013-01-26 nearly no change from 
update 2013-01-25. update 2013-01-26 Added 
[a name="docB808"] and [a name="docB809"]
and 710,492 logictt2_vc9_a20125_upload.htm
update 2013-01-26 main point is update 
logictt4.htm and logicmr2.htm 
Thank you for visiting 
2013-01-26-14-27 stop

<a name="docA129">
[a name="docA129"] match Chinese version.
2013-02-13-11-39 start
2013-02-07-06-20 LiuHH left landlord house 
walk to train station to L.A. Union Station
then to Gardena, then to Bakersfield Cal.
2013-02-11-16-56 sister send LiuHH back to 
Simi Valley California.
2013-02-13-11-40 stop

<a name="docA130">
2013-02-13-10-39 start 
Update 2013-02-13 has several minor change.
From 2013-01-27-08-14
  to 2013-02-05-17-48
LiuHH write Chinese version of logictt2.htm 
which is logictt1.htm 
During this ten days, made few small change.
In which the most important change is allow 
comment right to equation. For example, 
<a name="docA131">
earlier version must input as 
  ~A∧ ~P ∨~Q  
current version allow input as 
  ~A∧ ~P ∨~Q  //no group, ambiguous.
Key code is next line
a0=arr8[i0].indexOf('//'); //a201291521
program look for string '//' in first three 
lines. If '//' begin at left end, program 
skip this line. If '//' begin at middle point, 
program extract this line from left end up to 
'//' and not include '//'. 

<a name="docA132">
Above change started at example 31, line 3
Change 2nd line to  ((A→(B∨C))↔((S→T)∨(U→V)))  accepted in logicmr2.htm
logictt2.htm has no trouble, because left 
end 'Ch' is an error, 'Ch' is not a valid 
variable. This error simply cause skip line 3.
After write Chinese version, line 3 no 'Ch', 
all variable are valid, then next 'equation' 
let program stop output text truth table.

<a name="docA133">
After change, user can add '//' in line 1,2,3 
for comments. Line 4 and later, add '//' or not 
that has no difference. because program read 
only first three lines for three equations.
If '//' is not at left end and if '//' left 
side has no equation, have blank for example,
this will cause no text truth table output. 
~A//This line is OK, because ~A is a valid eq.
  //User should not input this way, left blank

Besides this '//' comments change, there are 
other changes, make explanation more clear.
2013-02-13-11-10 stop

<a name="docA134">
update 2013-11-16 document.
2013-11-15-09-50 start 
2013-11-09-16-25 LiuHH found that next
web site moved to
Compare with old URL
2013-11-09-16-27 try next found it is valid

<a name="docA135">
LiuHH decide in logictt2.htm not link to . Because Prof. Michael Rieppel 
may change domain name/folder name/file name 
in the future. Suggest reader visit
If this URL is invalid again, please search 
online with key words "Michael Rieppel" and 
"Truth Table Generator".
2013-11-15-09-57 stop

<a name="docA136">
2013-11-15-10-09 start 
2013-11-09-16-20 LiuHH access
it is Chinese ver. of logictt2.htm
2013-02-13 is previous update . 
Nine month not see logictt2.htm. Run default 
problem in Box01
LiuHH expect see answer right below Box01. 
But Box02 has debug output. LiuHH decide 
write update 2013-11-16. Let user see answer 
<a name="docA137">
update 2013-11-16 made following changes.
1. hyperlink
   change to #docA135
2. add HTML answer link right to Box02 line 
   right end. 
3. change Box02 two_input_equation output 
   from debug code to instruction where to 
   find answer. 
4. add <a name="htmlshow"> 
   Display Box03 HTML code truth table right  
   in logictt2.htm . Earlier version expect 
   reader copy/paste HTML code truth table 
   to reader's own page.
5. Change "line answer" to "Last line answer"
   Because this box record only last equation 
   T/F answer.
2013-11-15-10-42 stop

<a name="docA138">
2013-11-16-17-50 start
update 2013-11-16 modify 
update 2013-11-16 also modify next two files 
2013-11-16-17-53 stop

<a name="docA139">
2013-11-17-10-15 start
update 2013-11-17 modify at time stamp 
a211170942. 2013-11-16-21-55 found if take 
example 33 and delete "((~A∧ ~P)∨~Q)" 
change to next three lines
( ~A∧(~P ∨~Q)) //right two a group
  ~A∧ ~P ∨~Q  //no group, ambiguous.
which group do you mean? add () make your intention clear. //a201061842
third line " () " cause no output. 
a211170942 code use s2f1[][] not use 
eval(), solve problem.
2013-11-17-10-20 stop

¬ ~ ∨ ⊻ ∧ → ← ↔ | ⊽ ⇒ ⇐ ⇔ 

<a name="a056_002">
2012-06-21-11-10 Liu,Hsinhan access
06/21/2012 11:10 AM 831,293 LogicTeacher.pdf

2012-06-21-11-34 Liu,Hsinhan access
06/21/2012 10:36 AM 357,318 schmidt.ucg.ie_ma184_screen-4x4.pdf

<a name="a056_003">
2012-07-18-11-01 Liu,Hsinhan access
07/18/2012 10:03 AM 212,330 abstractmath.org_MM_MMConditional.htm

2012-07-18-11-09 Liu,Hsinhan access
07/18/2012 10:11 AM  57,185

<a name="a056_004">
2012-07-18-11-18 Liu,Hsinhan access
07/18/2012 10:21 AM 283,674 ksmodern1.com_Logic%20part%203.pdf

2012-11-23-10-15 Liu,Hsinhan access
11/23/2012 10:15 AM  41,216 ACaRA01.pdf

<a name="a056_005">
2012-11-23-10-32 Liu,Hsinhan access
11/23/2012 10:32 AM 588,180 chapter01.pdf

<a name="docB801">
12/04/2012  02:22 PM  61,506 logictt2_v01.htm
12/04/2012  05:01 PM  69,742 logictt2_v02_struggle.htm
12/04/2012  07:47 PM  80,504 logictt2_v03_a112041946.htm
12/04/2012  08:22 PM  59,774 logictt2_v04_a112041955_OK.htm
12/04/2012  11:46 PM  67,462 logictt2_v05_turn90degree.htm
12/05/2012  07:40 AM  73,886 logictt2_v06_a1120507_OK.htm
12/05/2012  07:57 AM  74,592 logictt2_v06_why_page_auto_change.htm
12/05/2012  07:52 AM  75,260 logictt2_v07_a1120507_hope_OK.htm
12/05/2012  10:01 PM  83,286 logictt2_v08_a112052157_a112052113.htm
12/06/2012  05:01 PM 101,206 logictt2_v09_a112061652_level_zero_OK.htm
12/06/2012  08:41 PM 105,176 logictt2_v10_wondering_dbg7.htm
12/07/2012  11:58 AM 107,348 logictt2_v11_a112071158_look_OK.htm
12/07/2012  02:36 PM 123,480 logictt2_v12_a112071436_m8_m9.htm
12/07/2012  04:59 PM 127,442 logictt2_v13_a112071649.htm
12/07/2012  07:56 PM 107,640 logictt2_v14_a112071947_struggle.htm
12/07/2012  08:32 PM 122,310 logictt2_v15_thin_sym2fun()_no_other_change.htm
<a name="docB802">
12/07/2012  11:08 PM 124,548 logictt2_v16_a112072301_OK.htm
12/08/2012  09:37 AM 138,186 logictt2_v17_a112080913_why_outer_redundant.htm
12/08/2012  01:41 PM 139,558 logictt2_v18_a112081338_why.htm
12/08/2012  01:49 PM 140,188 logictt2_v19_a112081345_ans.htm
12/08/2012  04:41 PM 142,934 logictt2_v20_a112081600_a112081417_both_OK.htm
12/08/2012  08:31 PM 113,548 logictt2_v21_sym2fun_v04_stop_work().htm
12/08/2012  08:40 PM  84,408 logictt2_v22_javascript_stop_work().htm
12/08/2012  10:42 PM  71,796 logictt2_v23_a11208_upload_v07.htm
12/09/2012  09:53 AM 141,746 logictt2_v24_sym2fun()_begin_work.htm
12/09/2012  04:03 PM 115,358 logictt2_v25_a112091603_oneLEqn[][].htm
12/09/2012  08:35 PM 123,874 logictt2_v26_a112052043_a112092035.htm
12/10/2012  12:21 AM 130,484 logictt2_v28_updatePQ().htm
12/10/2012  12:09 PM 137,272 logictt2_v29.htm
12/10/2012  01:02 PM 139,746 logictt2_v30_a112101257_oneLin3.htm
<a name="docB803">
12/10/2012  01:57 PM 142,274 logictt2_v31_a112101356_infinity.htm
12/10/2012  08:50 PM 144,686 logictt2_v32_a112102034_a112102042.htm
12/11/2012  11:48 AM 147,940 logictt2_v33_oneLinA[3]OK_a112111117.htm
12/11/2012  04:12 PM 154,356 logictt2_v34_convert_and_or.htm
12/11/2012  07:02 PM 160,314 logictt2_v35_a112111859_typeOf_typeof.htm
12/11/2012  08:27 PM 161,240 logictt2_v36_before_thin.htm
12/11/2012  08:36 PM 102,632 logictt2_v37_after_thin.htm
12/11/2012  10:05 PM 107,988 logictt2_v38_a112112134.htm
12/13/2012  04:11 PM  10,874 logictt2_v39_heart_code.htm
12/13/2012  04:02 PM 117,206 logictt2_v40_a1121315_a112131602.htm
12/13/2012  08:48 PM 131,482 logictt2_v41_a112132045_updateAnd().htm
12/13/2012  10:03 PM 130,200 logictt2_v42_a112132203_updateAnd().htm
12/13/2012  10:21 PM 131,192 logictt2_v43_a112132221_OK_right.htm
12/14/2012  06:37 PM 139,658 logictt2_v44_a112141809_add(_).htm
12/14/2012  09:40 PM 143,304 logictt2_v45_a112142117_iffift2.htm
<a name="docB804">
12/15/2012  04:30 AM 168,548 logictt2_v46_sym2fun1()_s2f1.htm
12/15/2012  02:13 PM 139,056 logictt2_v47_a112151413_updateAnd(iffift1).htm
12/15/2012  08:12 PM  21,486 logictt2_v48_updateAnd_v03()_only.htm
12/15/2012  09:42 PM 165,546 logictt2_v49_a112152136_a112152139.htm
12/16/2012  01:06 PM 160,930 logictt2_v50_a112161301_while().htm
12/16/2012  01:37 PM 166,478 logictt2_v51_near_done.htm
12/16/2012  08:11 PM 175,602 logictt2_v52_sym2fun1()_v04.htm
12/16/2012  10:22 PM 228,288 logictt2_v53_from_v51_partial_work.htm
12/17/2012  04:10 PM 194,226 logictt2_v54_first_all_right.htm
12/17/2012  09:00 PM 163,208 logictt2_v55_example_t_u_buttons.htm
12/18/2012  12:18 PM 144,560 logictt2_v56_thin_code_work.htm
12/18/2012  04:43 PM 146,508 logictt2_v57_a112181639_support_¬.htm
12/18/2012  07:32 PM 144,554 logictt2_v58_docA_start.htm
12/19/2012  11:03 AM 147,404 logictt2_v59_delete_QiftP.htm
12/19/2012  12:19 PM 153,276 logictt2_v60_docA_done.htm
<a name="docB805">
12/19/2012  07:43 PM 161,302 logictt2_v61_in_page_link_done.htm
12/20/2012  03:37 PM 168,032 logictt2_v62_a11220_upload.htm
12/21/2012  08:29 PM 173,420 logictt2_v63_toStandard().htm
12/22/2012  01:02 PM 181,232 logictt2_v64_run_line_1_2.htm
12/22/2012  07:09 PM 189,196 logictt2_v65_a11222_upload.htm
12/23/2012  03:13 AM 194,180 logictt2_v66_inp_oup_closer.htm
12/23/2012  02:01 PM 180,638 logictt2_v67_run_three_eq.htm
12/23/2012  05:51 PM 186,806 logictt2_v68_a11223_upload.htm
12/25/2012  07:56 AM 187,928 logictt2_v69_a112242357_a112242359.htm
12/31/2012  05:08 PM 195,520 logictt2_v70_a11231_upload.htm
12/31/2012  09:59 PM 201,620 logictt2_v71_PpulQ_PvulQ.htm
01/03/2013  11:52 AM 205,986 logictt2_v72_a201031008_newLogicSymb.htm
01/03/2013  06:58 PM 219,000 logictt2_v73_all_16_functions.htm
01/03/2013  10:04 PM 220,392 logictt2_v74_operator_and_alias_OK.htm
01/03/2013  11:13 PM 222,406 logictt2_v75_a201032310_use_vbyte_OK.htm
<a name="docB806">
01/04/2013  12:48 PM 234,994 logictt2_v76_run_1_2_3_eq.htm
01/04/2013  08:59 PM 223,166 logictt2_v77_trueFalse_0_1_OK.htm
01/04/2013  11:59 PM 227,168 logictt2_v78_ltto().htm
01/05/2013  02:22 PM 233,720 logictt2_v79_a201051251_a201051301.htm
01/05/2013  08:29 PM 239,960 logictt2_v80_a201051953_a201052002.htm
01/05/2013  08:53 PM 239,350 logictt2_v81_a201052053_add1_-1.htm
01/06/2013  12:44 PM 248,778 logictt2_v82_docA086.htm
01/06/2013  07:10 PM 261,428 logictt2_v83_done3rd_proofread.htm
01/06/2013  09:52 PM 258,778 logictt2_v84_a20106_upload.htm
01/07/2013  11:55 AM 259,340 logictt2_v85_2010711_lineAns0_X.htm
01/07/2013  12:53 PM 261,764 logictt2_v88_lineAnswer_Bx7_OK.htm
01/07/2013  03:52 PM 265,630 logictt2_v89_lineAnswer_compare.htm
01/07/2013  07:09 PM 273,922 logictt2_v90_a20107_upload.htm
<a name="docB807">
01/09/2013  11:40 AM 318,930 logictt2_v91_docC_bgn.htm
01/09/2013  10:10 PM 332,654 logictt2_v92_docC.htm
01/10/2013  12:31 PM 346,978 logictt2_v93_a201101225_why.htm
01/10/2013  05:38 PM 357,822 logictt2_v94_add_Box08.htm
01/11/2013  11:41 PM 369,994 logictt2_v95_deep_level_example_59.htm
01/12/2013  01:37 PM 384,564 logictt2_v96_docC_while(onePP[i0][2].eq.0).htm
01/12/2013  05:23 PM 394,178 logictt2_v97.htm
01/12/2013  07:27 PM 401,472 logictt2_v98.htm
01/13/2013  08:55 AM 408,304 logictt2_v99_a2011223.htm
01/13/2013  03:34 PM 419,802 logictt2_va0.htm
01/13/2013  10:10 PM 439,094 logictt2_va1.htm
01/14/2013  12:55 PM 429,352 logictt2_va1_sym2fun1()_noComment.htm
<a name="docB807why">
01/14/2013  02:58 PM 448,408 logictt2_va2_while(2)_forJ0exitAt_ERR.htm
when LiuHH save to logictt2_va2... it output error 
result, but at "a201141817 why" time, test run 
logictt2_va2 output right result, at same time 
logictt2_va4_a201141817_why.htm output error 
result before a201141817 correction, why?! 

<a name="docB808">
01/14/2013  03:22 PM 447,488 logictt2_va3_from_va1.htm
01/14/2013  06:20 PM 455,586 logictt2_va4_a201141817_why.htm
01/14/2013  08:04 PM 472,962 logictt2_va5_test_a201141957.htm
01/14/2013  09:19 PM 472,556 logictt2_va6_sym2fun1()_doc_done.htm
01/15/2013  12:16 PM 484,108 logictt2_va7_updateArr()_doc_done.htm
01/15/2013  08:27 PM 507,276 logictt2_va8_updateAnd()_doc_done.htm
01/15/2013  11:08 PM 509,776 logictt2_va9_a201152242_a201152245.htm
01/16/2013  08:15 PM 516,690 logictt2_vb0_updateAll()_doc_done.htm
01/17/2013  09:47 PM 555,758 logictt2_vb1_aname_docC345.htm
01/18/2013  10:41 AM 563,318 logictt2_vb2.htm
01/19/2013  10:00 AM 570,176 logictt2_vb3.htm
01/19/2013  06:28 PM 577,736 logictt2_vb4.htm
01/19/2013  09:20 PM 579,272 logictt2_vb5_a201192105_iff_ift.htm
01/20/2013  11:49 AM 581,804 logictt2_vb6_a201192105_a201201139.htm
01/20/2013  03:11 PM 582,022 logictt2_vb7.htm
01/20/2013  06:16 PM 584,578 logictt2_vb8_done_proofread.htm
<a name="docB809">
01/20/2013  07:22 PM 583,798 logictt2_vb9_a20120_upload.htm
01/21/2013  12:12 PM 605,978 logictt2_vc0_rewrite_updateStr().htm
01/21/2013  03:11 PM 620,164 logictt2_vc1_logic1Line()_bgn.htm
01/21/2013  11:25 PM 646,348 logictt2_vc2.htm
01/22/2013  03:18 PM 672,040 logictt2_vc3.htm
01/22/2013  10:43 PM 681,542 logictt2_vc4_a20122201_eqTF[i0].htm
01/23/2013  10:42 AM 689,008 logictt2_vc5_docC409.htm
01/24/2013  01:47 PM 698,468 logictt2_vc6_add_logicmr2_style_example.htm
01/24/2013  10:06 PM 699,998 logictt2_vc7.htm
01/25/2013  03:50 PM 704,798 logictt2_vc8_done_5th_proofread.htm
01/25/2013  06:37 PM 710,492 logictt2_vc9_a20125_upload.htm
01/26/2013  02:31 PM 711,682 logictt2_vd0_a20126_upload.htm
01/29/2013  10:35 AM 715,252 logictt2_vd1_xmpl31_a20129.htm
02/05/2013  05:17 PM 719,660 logictt2_vd2_a20206.htm
02/06/2013  01:36 PM 720,272 logictt2_vd3_a20206.htm
<a name="docB810">
02/13/2013  07:02 PM 725,036 logictt2_vd4_a20213_upload.htm
11/15/2013  08:45 AM 728,974 logictt2_vd5_a21115.htm
11/15/2013  11:03 AM 733,144 logictt2_vd6_a21115.htm

<a name=docC001">
2012-12-19-12-17 start 
Liu,Hsinhan will write logictt2.htm code 
document after LiuHH come back from trip.
Sister scheduled on 2012-12-24 
LiuHH (Simi Valley) and sister (Gardena) 
go to brother house (Bakersfield Cal.) 
Come back around 2013-01-02
2012-12-19-12-19 stop 

<a name=docC002">
2013-01-08-15-11 start 
The following is document for 
function sym2fun1(arg1) //a112051017 
function logic1Line(arg1) //a112041436 

<a name="docC003">
First describe the over all view. 
Example 37 equation //next line eq.37a
[{ ~A∧~P∨~Q→~R ∨ B∧C}↔(P→ <Q∨R> ∧ <Q∨A> )]
is fabricated for testing logictt2.htm. 
The following mark this equation as eq.37a.
'[' and ']' in eq.37a is part of equation.

eq.37a has space, has '{}', '[]', '<>' and 
has '()', parenthesis group is ambiguous. 
function sym2fun1() will convert eq.37a to
(~A∧~P∨~Q→~R∨B∧C)↔(P→(Q∨R)∧(Q∨A)) eq.37b
The following mark this equation as eq.37b.
<a name="docC004">
sym2fun1(arg1) will convert symbolic eq.37 
to code equation (function equation)
call it eq.37c. //above line eq.37c
Next, function logic1Line(arg1) receive 
eq.37c . logic1Line() find independent 
variables, A, B, C, P, Q, R. Assign 
true/false value to variables. Each one 
has true/false two possibilities. Six  
variables has total 2^6=64 different 
<a name="docC005">
function logic1Line(arg1) generate all 
64 combinations
At, Bt, Ct, Pt, Qt, Rt, 
At, Bt, Ct, Pt, Qt, Rf, 
At, Bt, Ct, Pt, Qf, Rt, 
Af, Bf, Cf, Pf, Qt, Rf, 
Af, Bf, Cf, Pf, Qf, Rt, 
Af, Bf, Cf, Pf, Qf, Rf, 
"At" is short of "A=true"
"Bf" is short of "B=false"
<a name="docC006">
then attach eq.37c to each line to form 
At, Bt, Ct, Pt, Qt, Rt, PiffQ((PiftQ(PiorQ(PandQ(notP(A),notP(P)),notP(Q)),PandQ(PiorQ(notP(R),B),C))),(PiftQ(P,PandQ((PiorQ(Q,R)),(PiorQ(Q,A))))))
At, Bt, Ct, Pt, Qt, Rf, ditto
At, Bt, Ct, Pt, Qf, Rt, ditto
Af, Bf, Cf, Pf, Qt, Rf, ditto
Af, Bf, Cf, Pf, Qf, Rt, ditto
Af, Bf, Cf, Pf, Qf, Rf, ditto
<a name="docC007">
complete line 
"A=true, B=true, C=true, P=true, Q=true, R=true, PiffQ((PiftQ(PiorQ(PandQ(notP(A),notP(P)),notP(Q)),PandQ(PiorQ(notP(R),B),C))),(PiftQ(P,PandQ((PiorQ(Q,R)),(PiorQ(Q,A))))))"
is a text string of one unknown. 
logic1Line(arg1) call function 
eval(complete line) 
to get true/false answer, 
64 combination call eval() 64 times 
to build final answer table.
At, Bt, Ct, Pt, Qt, Rt,  true
At, Bt, Ct, Pt, Qt, Rf,  true
At, Bt, Ct, Pt, Qf, Rt,  true
Af, Bf, Cf, Pf, Qt, Rf,  false
Af, Bf, Cf, Pf, Qf, Rt,  false
Af, Bf, Cf, Pf, Qf, Rf,  false
<a name="docC008">
To make eq.37c work, LiuHH defined seven 
frequently used P___Q(arg1,arg2) functions.
Defined one negation function notP(arg1).
Defined nine rare used PrrrQ(arg1,arg2) 
functions. Frequently used functions are 
AND operation PandQ(arg1,arg2)
OR  operation PiorQ(arg1,arg2)
if,then op.   PiftQ(arg1,arg2)
if only if op PiffQ(arg1,arg2)
NAND operat.  PvulQ(arg1,arg2)
NOR operation PpulQ(arg1,arg2)
XOR operation PxorQ(arg1,arg2)
<a name="docC009">
Above is Liu,Hsinhan logictt2.htm method. 
Below is Michael Rieppel's logicmr2.htm 
LiuHH will not write logicmr2.htm code 
document. Here discuss Rieppel's method.
logicmr2 do not accept ambiguous (~A&~Pv~Q) 
logicmr2 ask user input precise equation 
((~A&~P)v~Q) or (~A&(~Pv~Q)) both are OK. 
logicmr2 do not worry group (~A&~Pv~Q) to 
((~A&~P)v~Q) or to (~A&(~Pv~Q)) 
<a name="docC010">
Rieppel's method look for six operators 
~, &, v, >, =, |
Negation ~ has only right hand side eq. 
&, v, >, =, | each has both side equation.
If input is "((~A&~P)v~Q)" 
operator 'v' evaluate "(~A&~P)" and "~Q"
To evaluate "(~A&~P)", call same evaluation 
function for operator "&". A and P are 
elementary variables. A,P has T/F value 
assigned by program. Answer for "(~A&~P)" 
send back to "v" at "((~A&~P)v~Q)", then 
final answer is in hand.
<a name="docC011">
LiuHH defined seven P___Q() functions.
Rieppel's equivalent code is not in 
function form. It is if-then form. This 
if-then structure allow Rieppel avoid 
use function eval() it is different 
from LiuHH's rely on eval() method. 
Which method is better? 
<a name="docC012">
Rieppel's method is better for two 
1. Danny Goodman’s JavaScript Bible 5th 
   edition suggest reader do not use 
   function eval() for efficiency reason.
   page 207 (236 of 1748)
You can access any element that has an identifier 
assigned to its id attribute by that identifier
in string form (as well as by index integer). 
Rather than use the performance-costly eval()
function to convert a string to an object reference.
   Rieppel's method not call eval().
   LiuHH method main engine is eval(). 
<a name="docC013">
2. Rieppel's code logicmr2.htm not only 
   give Main Connective T/F answer, but 
   also provide Full Table T/F value. 
   LiuHH method logictt2.htm did not give 
   full table T/F value.
If reader do not care speed (efficiency), 
and need only main connective T/F answer, 
and like to get a copy of html table code 
for your web page, logictt2.htm is still 
a collectable code after logicmr2.htm .
2013-01-08-16-30 stop 

<a name="docC014">
2013-01-08-20-00 start 
sym2fun1(arg1) is an important function. 
it change symbolic equation to function 
equation. Simple example 
change from (P∨Q) to (PiorQ(P,Q))
A little involve example, change 
(P → Q) ∨ (Q → P)  to //example 21, eq.21a 
PiorQ(PiftQ(P,Q),PiftQ(Q,P)) ---eq.21c
<a name="docC015">
logictt2.htm allow user input ambiguous 
(~A∧~P∨~Q) ---eq.A1a
sym2fun1() choose one from two possibilities 
either ((~A∧~P)∨~Q) ---eq.A1b
       ans. F,T,F,T,F,T,T,T
or     (~A∧(~P∨~Q)) ---eq.A1c
       ans. F,F,F,F,F,T,T,T
LogicTeacher.pdf page 32/231 instruct 
Evaluate ∨ and ∧ second. When both 
are present, parenthesis may be needed, 
otherwise work left to right.
Ambiguous (~A∧~P∨~Q) ---eq.A1a
is coded to become 
((~A∧~P)∨~Q) ---eq.A1b //code do this job 
<a name="docC016">
Enter function, check input argument is 
string or not.
function sym2fun1(arg1)
{ //a112051017
return 'sym2fun1(arg1) error 01\n'
+'arg1 must be a string type, \n'
+'now typeof(arg1)='+typeof(arg1)+'\n'

<a name="docC017">
javascript variable can be any type:  
string, integer, float number, array, 
Boolean etc. Convert symbol equation 
to function equation, the input must 
be a string type. If call sym2fun1(8)
typeof(arg1)=typeof(8)=integer, code 
return error 01.
2013-01-08-20-28 here

<a name="docC018"> var i0,j0,k0; var i1,j1,k1; var i2,j2,k2; var m0,m1,m2,m3,m4,m5,m6,m7,m8,m9; var n0,n1,n2,n3,n4,n5,n6,n7,n8,n9; var p0,p1,p2,p3; var ans0=''; var arr0; This block is variable declaration.
<a name="docC019"> if(arg1.indexOf('\r\n')>=0) arr0=arg1.split('\r\n'); else if(arg1.indexOf('\n')>=0) arr0=arg1.split('\n'); else arr0=arg1.split('\r'); var oneLine=''; var historyArr=[]; var hA=0; <a name="docC020"> logictt2.htm allow user input up to three equations. Each take one line. Below equation can be document lines. WindowsXP, Windows7 MSIE input box use '\r\n' to separate lines. Windows8 MSIE input box use '\n' to separate lines. Some other operating system may have input box use '\r' to separate lines. <a name="docC021"> Above code split input string at new line bytes. Before split, arg1 is a string like arg1="(P ∨ Q)\n(Q ∧ P)\ndoc here." ---eq.A2a After arg1.split(newline) output to arr0=["(P ∨ Q)", "(Q ∧ P)", "doc here."] ---eq.A2b <a name="docC022"> arr0 is an array of three strings. Code is possible to check arr0[0]="(P ∨ Q)" is it an equation? arr0[1]="(Q ∧ P)" is it an equation? arr0[2]="doc here." is it an equation? If it is equation, convert to function equation (same as code equation) <a name="docC023"> var oneLine=''; is one line equation, for example "(Q ∧ P)" sym2fun1() change "(Q ∧ P)" step by step. After each change, code record that step equation in historyArr[] var historyArr=[]; var hA=0; historyArr[] has array index hA. It is easy to write code historyArr[hA++]=oneLine; Record equation and update index in one code line. 2013-01-08-20-45 here
<a name="docC024"> for(i0=0;i0<arr0.length;i0++) { historyArr[0]=arr0[i0]; if(historyArr[0].length==0) return 'sym2fun1(arg1) error 02\n' +'Input line is empty.\na112051021\n' Above for(i0) loop hint sym2fun1(arg1) read multiple line input. Actually current version sym2fun1(arg1) read just one line input. function runEqn(*,*) feed one line equation to sym2fun1(arg1) at one time. Related code line is j0=sym2fun1(arr8[i0]); 2013-01-18-16-32 <a name="docC025"> Above example get arr0=["(P ∨ Q)", "(Q ∧ P)", "doc here."] ---eq.A2b for(i0=0;i0<arr0.length;i0++) is in fact for(i0=0;i0<3;i0++) because arr0 has 3 elements, then arr0.length=3. i0 will get value 0,1,2. When i0=0, arr0[i0]=arr0[0]="(P ∨ Q)" When i0=1, arr0[i0]=arr0[1]="(Q ∧ P)" When i0=2, arr0[i0]=arr0[2]="doc here." <a name="docC026"> historyArr[0]=arr0[i0]; [0] record user input to historyArr[] Why it is "user input"? because no modification take place up to here. <a name="docC027"> If input is Box01, input function runEqn(*,*) feed one line equation to sym2fun1(arg1) First line is empty, sym2fun1(arg1) has arg1="", and arr0=[""] when i0=0, historyArr[0]="". Empty string length is zero. if(historyArr[0].length==0) is true, return sym2fun1(arg1) error 02 2013-01-08-20-58 stop
<a name="docC028"> for(j0=0;j0<historyArr[0].length;j0++) { //if(ubyte.indexOf(historyArr[0].charAt(j0))>=0) //a201032310 change ubyte to vbyte if(vbyte.indexOf(historyArr[0].charAt(j0))>=0) break; } if(j0<historyArr[0].length)break; } //for(i0=0;i0<arr0.length;i0++) <a name="docC029"> 2013-01-09-10-30 start Above code in user input equation search for operator bytes. If find one, this line is equation, otherwise it is a comment line and stop building truth table. User input equation is stored in historyArr[0]. Operator definition is ubyte="~∨⊻∧→←↔⇒⇐⇔|⊽乙人丩力匕卜厂又"; and //vbyte date stamp a201032305 vbyte="¬~!∨#+⊕⊻$∧&*•|↑⊼↓⊽→⇒↔⇔=←⇐乙人丩力匕卜厂又"; Why two operator string? answer <a name="docC030"> Earlier version has just one definition. ubyte="~∨⊻∧→←↔⇒⇐⇔"; //a112042200 Later read more online logic pages, find there are several other operator usage. LiuHH decide to include most of those operators, let user free from conversion. After this operator expansion, need two definition strings. ubyte twenty operators are in s2f1[*][0] operator to function name matching table. vbyte include ubyte and extra operators. <a name="docC031"> For example AND operator, logictt2.htm accept ∧,&,*,•. They are all listed in vbyte. Only ∧ is in ubyte, because only ∧ is in matching table s2f1[][]. &,*,• are not in table s2f1[][]. Those in s2f1[][] are standard operator, other operator convert to standard. <a name="docC032"> var s2f1= [['~', 'notP'], ['∨', 'PiorQ'], ['⊻', 'PxorQ'], //~(P↔Q) ['∧', 'PandQ'], ['→', 'PiftQ'], ['←', 'PfulQ'], ['↔', 'PiffQ'], ['⇒', 'PiftQ'], ['⇐', 'PfulQ'], ['⇔', 'PiffQ'], ['|', 'PvulQ'], //a112311954 PvulQ() nand==~(P∧Q), Sheffer Stroke ['⊽', 'PpulQ'], //a112312135 PpulQ() nor == ~(P∨Q) <a name="docC033"> //dul,nul etc. 乙人丩力匕卜厂又 ['乙', 'PdulQ'], //always true, dull ['人', 'PgulQ'], //always P, ignore Q ['丩', 'PhulQ'], //always Q, ignore P ['力', 'PtulQ'], //always~Q, ignore P ['匕', 'PsulQ'], //~(P→Q) ['卜', 'PrulQ'], //always~P, ignore Q ['厂', 'PqulQ'], //~(P←Q) ['又', 'PnulQ'] //always false, null ] //s2f1[][] <a name="docC034"> The building of ubyte is automatic. Program read s2f1[][], collect s2f1[*][0] to build ubyte. var ubyte=''; //a201032046 for(var ii=0;ii<s2f1.length;ii++) ubyte+=s2f1[ii][0]; //a201032047 Above s2f1[][] definition and for(var ii) loop are both in global view area. They are not in any function body. s2f1[] and ubyte can be used by any function code. <a name="docC035"> function sym2fun1(arg1) job is to convert user input "A&B" to PandQ(A,B). Before conversion, code exam current input line has operator or not? Here, if code use ubyte (error) to exam input line, then user input "A&B" is not an equation. Before conversion, code exam input line must use vbyte. In vbyte, "&" is an operator. Later code change "&" to "∧", then it is possible read function name PandQ from s2f1[] line ['∧', 'PandQ']. After an error, code NOT recognize "A&B" then LiuHH realize, before conversion, must use vbyte, not ubyte. <a name="docC036"> Code line if(vbyte.indexOf(historyArr[0].charAt(j0))>=0) break; say in vbyte string search for user input line historyArr[0] current byte j0, see if this byte is in vbyte. Assume current user input line is "A&B" Re-state above sentence with code: in "A&B" search for second (j0=1) byte "&", see whether "&" is in vbyte string vbyte="¬~!∨#+⊕⊻$∧&*•|↑⊼↓⊽→⇒↔⇔=←⇐乙人丩力匕卜厂又"; <a name="docC037"> historyArr[0]="A&B" is user input line. historyArr[0].charAt(j0) j0 scan from j0=0, j0=1 to j0=2. When j0=0 historyArr[0].charAt(0) is "A&B".charAt(0) is "A", but "A" is not in vbyte. Next j0=1 historyArr[0].charAt(1) is "A&B".charAt(1) is "&", now "&" IS in vbyte. Break from for(j0) loop. After exit for(j0) loop, flow is still in for(i0) loop, next code check if(j0<historyArr[0].length)break; whether find operator? If yes, break from outer for(i0) loop. Otherwise read next user input line. <a name="docC038"> Now user input line "A&B" has "&" at j0=1 position, break and j0=1 not change again. "A&B" has 3 bytes. Code line if(j0<historyArr[0].length)break; compare j0 with historyArr[0].length=3 . j0 is 1, historyArr[0].length="A&B".length 1<3 is true, break from for(i0) loop. Alert! already break from for(j0) loop. Next code is if(j0==historyArr[0].length) return historyArr[0]; j0==historyArr[0].length say in user equation historyArr[0], no one byte found in vbyte , that is user equation do not have operator. <a name="docC039"> Example 7 is [[ PiffQ(PiftQ(P,Q),PiorQ(P,notP(Q))) (P→Q)↔((P)∨(~Q)) chapter01.pdf page 18/72 eq.1.8 but ~ flip a112031429 ]] First line is code equation, it is an equation with function calls, it is not a symbolic equation. function equation do not have any operator and function equation is perfect OK in logictt2.htm. Return without change "&" to "∧" (and nothing to change) allow program run user input function equation. <a name="docC040"> If not return, following code do "&" to "∧" conversion. historyArr[] will record more equation, let historyArr[] counter hA increase by one hA++, for next history record. 2013-01-09-12-18 stop
<a name="docC041"> 2013-01-09-19-49 start The following code convert '{}','[]','<>' to '()'. oneLine=historyArr[0].replace(/\[/g,'(').replace(/\]/g,')').replace(/\{/g,'(').replace(/\}/g,')').replace(/\</g,'(').replace(/\>/g,')').replace(/ /g,'').replace(/\t/g,''); Above one line is next four in one oneLine=historyArr[0].replace(/\[/g,'(').replace(/\]/g,')') oneLine=oneLine.replace(/\{/g,'(').replace(/\}/g,')') oneLine=oneLine.replace(/\</g,'(').replace(/\>/g,')') oneLine=oneLine.replace(/ /g,'').replace(/\t/g,''); First line change from '[]' to '()'. Second line change from '{}' to '()'. Third line change from '<>' to '()'. Fourth line delete blank and tab. <a name="docC042"> This line convert "{}","[]","<>" to "()" logictt2.htm allow reader use "{}", "[]", "<>" and "()" in logic equation. They let reader see matching boundary better. But code process only "()". Here convert non-standard to standard "()". Logic equation no need space, first line right most replace delete ' ' and delete tab.
<a name="docC043"> n5=matchParenthesis(oneLine); //a201051955 if(typeof(n5)=='string')return n5; //a201052024 if(j0==historyArr[0].length) return historyArr[0]; //a112221157 hA++; <a name="docC044"> 2013-01-16-16-29 new doc start There are several replacement code here. .replace(/\[/g,'(').replace(/\]/g,')') change quote from '[]' to '()' .replace(/¬/g,'~') change '¬A' to '~A' .replace(/#/g,'∨') change 'A#B' to 'A∨B' etc. But after quote change and before operator change, there is one thing to do. Check whether quote balance is true or not. quote include '{}', '[]', '<>', '()'. <a name="docC045"> This arrangement allow code equation input, for example PiffQ(notP(PiorQ(P,Q)),PandQ(notP(P),notP(Q))) and symbolic equation input, for example (~(P∨Q))↔((~P)∧(~Q)) ---eq.01a share one parenthesis pair balance check. Earlier structure exam '()' balance twice. Now merge to one. n5=matchParenthesis(oneLine); //a201051955 If input equation quotes not balance, n5 is a string of error message. Return error at if(typeof(n5)=='string')return n5; //a201052024 <a name="docC046"> Early code for(j0=0;j0<historyArr[0].length;j0++) if(vbyte.indexOf(historyArr[0].charAt(j0))>=0) break; use j0 scan input equation historyArr[0], see if input has any operator bytes (vbyte). If input is code equation 'PiorQ(A,B)' there is no operator byte in it. Then j0==historyArr[0].length and stop. <a name="docC047"> Code line if(j0==historyArr[0].length) return historyArr[0]; send code equation back. No operator, no work to do. Otherwise, input has operator bytes, code line hA++; increase history array counter by one. Let next history array record not erase current user input equation. 2013-01-16-16-55 new doc stop
<a name="docC048"> The following code convert non-standard operator to logictt2.htm standard. oneLine=oneLine.replace(/¬/g,'~'); //a112181420 oneLine=oneLine.replace(/!/g,'~'); //a201032035 //oneLine=oneLine.replace(/#/g,'∨').replace(/+/g,'∨'); //a201032036 //a201032138 above line error, + to \+ OK oneLine=oneLine.replace(/#/g,'∨').replace(/\+/g,'∨'); //a201032036 oneLine=oneLine.replace(/=/g,'↔'); //a201032037 <a name="docC049"> //first line is here Second and third line replace "¬" to "~" replace "!" to "~". All three are used by different web page author for negation expression. logictt2 use "~" as standard. Some author use "#", "+" for OR operation, logictt2 use "∨" as standard. Some author use "=" for if and only if operation, logictt2 use "↔" as standard.
<a name="docC050"> //oneLine=oneLine.replace(/&/g,'∧').replace(/*/g,'∧').replace(/•/g,'∧'); //a201032038 //a201032140 above line error, * to \* OK oneLine=oneLine.replace(/&/g,'∧').replace(/\*/g,'∧').replace(/•/g,'∧'); //a201032038 oneLine=oneLine.replace(/↑/g,'|').replace(/⊼/g,'|'); //a201032040 //oneLine=oneLine.replace(/⊕/g,'⊻').replace(/$/g,'⊻'); //a201032041 //a201032146 above line error, $ to \$ OK oneLine=oneLine.replace(/⊕/g,'⊻').replace(/\$/g,'⊻'); //a201032041 oneLine=oneLine.replace(/↓/g,'⊽'); //a201032042 <a name="docC051"> AND operator can be "∧", "&", "*", "•" logictt2 use "∧" as AND operation standard. NAND operator can be "|", "↑", "⊼". It is Sheffer Stroke. Liu,Hsinhan first time see Sheffer Stroke at Professor Michael Rieppel use "|" as operator, logictt2.htm take "|" as standard operator. Other symbol "↑", "⊼" change to "|". <a name="docC052"> XOR operator can be "⊕", "⊻", "$". logictt2 use "⊻" as XOR operation standard. NOR operator can be "↓", "⊽". logictt2 use "⊽" as NOR operation standard. 2013-01-09-20-12 here "docC053", "docC054", "docC055" deleted
<a name="docC056"> Store the result of above 21 replacements to history array at next first red line. historyArr[hA++]=oneLine; var upper26='ABCDEFGHIJKLMNOPQRSTUVWXYZ'; var upLow52='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +'abcdefghijklmnopqrstuvwxyz'; <a name="docC057"> Logic equation independent variable allow English 26 uppercase alphabets which is defined in variable upper26. Logic function name are P___Q() type, where "_" is English 26 lowercase alphabets, for example PandQ(). Logic function name must be found in upLow52.
<a name="docC058"> var upArray=new Array(26); for(i0=0;i0<upArray.length;i0++) upArray[i0]=0; User's equation has what independent variable? Program must be able to find them. Since total allow 26 uppercase alphabets. <a name="docC059"> Now create an array upArray with 26 seats. Code below scan user equation, if see independent variable, sum it in upArray[]. Before summation, must initialize 26 seats to 26 zeros. If not initialize, javascript do not know upArray[0] to upArray[25] will store what type data. If store string, initial upArray[0]=''. If store integer, initial upArray[0]=0. etc. Here, we need initialize with 0. 2013-01-09-20-36 here
<a name="docC060"> for(i0=0;i0<oneLine.length;i0++) { j0=upper26.indexOf(oneLine.charAt(i0)); if(j0<0)continue; Assume user input equation "P∧Q". then variable oneLine="P∧Q" On the other hand upper26='ABCDEFGHIJKLMNOPQRSTUVWXYZ'; <a name="docC061"> Code line for(i0=0;i0<oneLine.length;i0++) say let variable i0 scan over oneLine, from i0=0 to i0<oneLine.length, that is from i0=0 to i0<"P∧Q".length, that is from i0=0 to i0<3. i0 take value 0,1,2. When i0=0, oneLine.charAt(i0)="P". When i0=1, oneLine.charAt(i0)="∧". When i0=2, oneLine.charAt(i0)="Q". When i0=3, oneLine.charAt(i0)='undefined'.
<a name="docC062"> If user input were "aP∧Q", trigger next error message. if(i0>0&&upLow52.indexOf(oneLine.charAt(i0-1))>=0) return 'sym2fun1(arg1) error 05 \n' +'allow only uppercase one byte \n' +'logic basic symbol. Can not use \n' +'two bytes as basic symbol, can \n' +'not include logic function name \n' +'Example "PiffQ" is not allowed.\n' +'Now in \n'+oneLine+'\n' +'find '+oneLine.charAt(i0-1) +oneLine.charAt(i0)+'\na112061606\n'; <a name="docC063"> If user input were "aP∧Q" oneLine.charAt(0)="a". oneLine.charAt(1)="P". oneLine.charAt(2)="∧". oneLine.charAt(3)="Q". Lowercase "a" is not in upper26='ABCDEFGHIJKLMNOPQRSTUVWXYZ' 2013-01-09-21-00 test run "aP∧Q", why nothing happen? 2013-01-09-21-23 correction at "a201092123 del" //+'Now in \n'+oneLin0+'\n' //a201092123 del +'Now in \n'+oneLine+'\n' //oneLine correct <a name="docC064"> 2013-01-09-21-33 continue "a" is not in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' not find "a" get j0=-1<0 continue to i0=1 for oneLine.charAt(1)="P". "P" is in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' j0=15 >0 come to next code line if(i0>0&&upLow52.indexOf(oneLine.charAt(i0-1))>=0) Require i0>0 because .charAt(i0-1) look at i0-1, if i0==0, i0-1 get -1, -1 is not an index value. -1 mean not found . <a name="docC065"> Now "aP∧Q" 'P' is i0=1>0, oneLine.charAt(i0-1) is 'a'. Search logic variable, use upper26 Find wrong logic variable, use upLow52. 'a' is in upLow52 return 'sym2fun1(arg1) error 05' In logictt2.htm, "aP" is not allowed as a logic variable. 2013-01-09-21-49 here
<a name="docC066"> if(i0<oneLine.length-1&& upLow52.indexOf(oneLine.charAt(i0+1))>=0) { return 'sym2fun1(arg1) error 06 \n' +'allow only uppercase one byte \n' +'logic basic symbol. Can not use \n' +'two bytes as basic symbol, can \n' +'not include logic function name \n' +'Example "PiffQ" is not allowed.\n' +'Now in \n'+oneLine+'\n' +'find '+oneLine.charAt(i0) +oneLine.charAt(i0+1)+'\na112061607\n' +'If click [2St] before click [run Box01 equation]\n' +'function toStandard() may correct problem. a201051717\n' ; } upArray[j0]++; } //for(i0=0;i0<oneLine.length;i0++) <a name="docC067"> Code line if(i0<oneLine.length-1&& upLow52.indexOf(oneLine.charAt(i0+1))>=0) require i0<oneLine.length-1 because oneLine.charAt(i0+1) has i0+1 if i0=oneLine.length-2<oneLine.length-1 then i0+1 is (oneLine.length-2)+1 that is oneLine.length-1, which is last byte in string "aP∧Q" <a name="docC068"> return 'sym2fun1(arg1) error 06' has same reason as return 'sym2fun1(arg1) error 05' In logictt2.htm, "Pb" is not allowed as a logic variable. However, 'sym2fun1(arg1) error 06' has one more hint <a name="docC069"> 'If click [2St] before click [run Box01 equation]\n' 'function toStandard() may correct problem. a201051717\n' This is designed for Michael Rieppel style equation "(~A&(~Pv~Q))" here 'v' is OR operator. If user click [2St] button, "(~A&(~Pv~Q))" change to "(~A∧(~P∨~Q))" In logicmr2.htm use "(~A&(~Pv~Q))" In logictt2.htm use "(~A∧(~P∨~Q))" //drop outer ["] If no error return, control flow to upArray[j0]++; <a name="docC070"> If user input "P∧Q", then 'P' in "P∧Q" result upArray[j0]++ or upArray[15]++, or upArray[15]=0+1=1 'Q' in "P∧Q" result upArray[j0]++ or upArray[16]++, or upArray[16]=0+1=1 Why 15,16? see next three lines. upper26='ABCDEFGHIJKLMNOPQRSTUVWXYZ'; 01234567890123456789 0 1 1 'P' marked red for better view. 2013-01-09-22-10 stop
<a name="docC071"> 2013-01-10-10-03 start Assume input equation is (B∨C)→(B∧C) Output to
BC answer
TT true
TF false
FT false
FF true
Table width:
<a name="docC072"> upArray[] will store the following upArray= [0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z'; Red color is real stored value, black color is reference, tell you count for which. upArray has 26 elements, in "(B∨C)→(B∧C)" only two B and C are used as logic variable. Next code line variable elemStr record only alphabet sum to value greater than zero. <a name="docC073"> var elemStr=''; for(i0=0;i0<upArray.length;i0++) if(upArray[i0]>0)elemStr+=upper26.charAt(i0); upArray[i0] has only summation numbers. upper26='ABCDEFGHIJKLMNOPQRSTUVWXYZ'; 01234567890123456789 If upArray[i0]>0, then elemStr record i0 th element in upper26. Input equation (B∨C)→(B∧C) has two 'B' and 'B' has index i0=1, upArray[i0]=upArray[1]=2; //find two 'B' upper26.charAt(i0)=upper26.charAt(1)='B' elemStr record one 'B' become elemStr="B" //was elemStr="". <a name="docC074"> Similarly, when i0=2 upArray[i0]=upArray[2]=2; //find two 'C' upper26.charAt(i0)=upper26.charAt(2)='C' elemStr record one 'C' become elemStr="BC" //was elemStr="B". No other alphabet and elemStr="BC" is final. This elemStr="BC" is used to build output html table left two columns. 2013-01-10-10-26 here
<a name="docC075"> var eL=elemStr.length; if(eL==0) return 'sym2fun1(arg1) error 03\n' +'Input equation do not have one\n' +'byte uppercase independent variable.\n' +'first line=\n'+oneLine+'\n' +'a112041530\n'; <a name="docC076"> eL record the length of elemStr="BC". Later code use shorter eL, not use longer elemStr.length . In the example (B∨C)→(B∧C) eL=2 for B and C two are used. If input equation is "(∨)→(∧)" return 'sym2fun1(arg1) error 03'
<a name="docC077"> Next variable "onePP" mean oneLine Parenthesis Pair result. var onePP=matchParenthesis(oneLine); if(typeof(onePP)=='string')return onePP; if(onePP.length==1&&onePP[0][0]==-1) { //a201181928 example 38 enter this if() oneLine='('+oneLine+')'; historyArr[hA-1]=oneLine; onePP=matchParenthesis(oneLine); } If function matchParenthesis() return a string answer, that mean oneLine has error, '(' count and ')' count are different. Return the error and stop sym2fun1(arg1). <a name="docC078"> If matchParenthesis() send back a strange array [[-1]]. It tell us that input string do not have even one '(', ')'. Example 38 ~A∧~B∨~C→~D∨E∧F↔G∨~H∧I ---eq.38a do not have '(', ')' , code line oneLine='('+oneLine+')'; add '(', ')' for this equation. Become (~A∧~B∨~C→~D∨E∧F↔G∨~H∧I) code line historyArr[hA-1]=oneLine; erase no parenthesis record, change to parenthesis_added equation. This erase and re-write is after user input historyArr[0], user's input not change. <a name="docC079"> After add '(', ')', code line onePP=matchParenthesis(oneLine); re-do parenthesis pair analysis. Following code rely upon function matchParenthesis() returned array, changed equation, re-do analysis is necessary. 2013-01-10-11-13 here
<a name="docC080"> logictt2.htm tolerate outer redundant extra '(', ')'. Next code remove them. Example 32 has outer redundant //a112080928 (((P∨Q)→R)↔((P→R)∧(Q→R))) ---eq.32a matchParenthesis() return the following [[ pstrDol= ((())(()())) (((P_Q)_R)_((P_R)_(Q_R))) 0123456789012345678901234 0 1 2 <a name="docC081"> 2,6, level=0 12,16, level=0 18,22, level=0 1,9, level=1 11,23, level=1 0,24, level=2 ]] outer 0,24, level=2 is redundant '()'. <a name="docC082"> Input equation is (((P∨Q)→R)↔((P→R)∧(Q→R))) ---eq.32a Analysis code use (((P_Q)_R)_((P_R)_(Q_R))) ---eq.32b Unicode "∨→↔→∧" are wider than Ascii code. Ascii code align with ruler better (((P_Q)_R)_((P_R)_(Q_R))) <==Ascii code 0123456789012345678901234 <==ruler ones 0 1 22222 <==ruler tens Equation length is 25 bytes long, start from 0, end at 24, that is 25 bytes long. <a name="docC083"> Parenthesis pair analysis result is onePP= //onePP.length=6 [[2,6, 0], //onePP[0] [12,16, 0], //onePP[1] [18,22, 0], //etc. [1,9, 1], [11,23, 1], [0,24, 2]] First row (row index number 0) [2,6, 0] say (((P_Q)_R)_((P_R)_(Q_R))) 0123456789012345678901234 ruler location 2,6 has one matching pair. This pair '(', ')' is level zero. level zero mean within this pair, no other parenthesis pair exist. <a name="docC084"> Fifth row (row index number 4) [11,23, 1] say (((P_Q)_R)_((P_R)_(Q_R))) 0123456789012345678901234 0 11 2222 ruler location 11,23 has one matching pair. This pair '(', ')' is level one. level one mean within this pair, there is at least one level zero parenthesis pair exist. In above example, two level zero pairs enclosed in level one. <a name="docC085"> Sixth row (row index number 5) [0,24, 2] say (((P_Q)_R)_((P_R)_(Q_R))) 0123456789012345678901234 0 1 22222 ruler location 0,24 has one matching pair. This pair '(', ')' is level two. level two mean within this pair, there is at least one level one parenthesis pair exist. In above example, two level one pairs enclosed in level two. <a name="docC086"> Following code remove outer redundant j0=0; for(i0=onePP.length-1;i0>0;i0--) { if(onePP[i0][0]==j0 &&onePP[i0][1]==(oneLine.length-1-j0) ) j0++ else break; } All redundant '(', ')' pair are highest level. To remove them start from highest. <a name="docC087"> i0=onePP.length-1 i0 start from onePP.length-1 onePP.length=6 i0 start from 6-1=5 onePP[i0]= [0,24, 2] onePP[i0][0]= 0 // left '(' location onePP[i0][1]=24 //right ')' location onePP[i0][2]= 2 //level 2 j0 start at j0=0; NOT at j0=1; <a name="docC088"> Code line if(onePP[i0][0]==j0 &&onePP[i0][1]==(oneLine.length-1-j0) ) j0++ say if onePP[i0=5][0]==j0 and if onePP[i0=5][1]==(oneLine.length-1-j0) that is say if 0==0 and if 24==(25-1-0) //equation length 25 bytes then increase j0 by one. Above two "if" are both true, j0++ from j0=0 to j0=1. If outer most parenthesis pair has one '~' left to them, index 0 point to '~', index 1 point to '(', above onePP[i0=5][0]==j0 1==0 is false, then not remove outer most '()'. <a name="docC089"> If outer most parenthesis pair do not have '~' left to them, continue work. Next iteration is i0-- evaluation. i0 start from i0=5, -- to i0=4 Now use i0=4 and j0=1 to evaluate. i0==4 meet [11,23, 1] if onePP[i0=4][0]==j0 ? or if 11==1 ? false, break from for(i0) loop. If input were ((( ((P∨Q)→R)↔((P→R)∧(Q→R)) ))) j0 will increase to j0=3 and break. ~((( ((P∨Q)→R)↔((P→R)∧(Q→R)) ))) is error. 2013-01-10-12-14 stop
<a name="docC090"> 2013-01-10-13-30 start At this point, j0 has number of outer redundant parenthesis pairs. Following code, remove them. oneLine=oneLine.substring(j0,oneLine.length-1-j0+1); historyArr[hA++]=oneLine; onePP=matchParenthesis(historyArr[2]); if(typeof(onePP)=='string')return onePP; <a name="docC091"> The code line oneLine=oneLine.substring(bgn0,end0) take oneLine substring, start from bgn0 to end0, save result back to oneLine. bgn0 is first byte to record. end0 is first byte NOT to record. first byte to record is j0 first byte NOT to record is length-1-j0+1 <a name="docC092"> Example equation (((P∨Q)→R)↔((P→R)∧(Q→R))) ---eq.32a has just one outer redundant parenthesis pais. j0=1 is easy to see, below. j0 is first byte we want to record. (((P∨Q)→R)↔((P→R)∧(Q→R))) ---eq.32a <== input Unicode equation (((P_Q)_R)_((P_R)_(Q_R))) <==Ascii code 0123456789012345678901234 <==ruler ones 00 1 22222 <==red is we want to record. end0 is first byte NOT to record end0=length-1-j0+1=length-1-1+1=25-1-1+1=24 <a name="docC093"> equation length is 25 characters. length-1 point to 25-1=24 length-1-j0 skip redundant ')', length-1-j0 point to 23. length-1-j0+1 move pointer to right one space. Because end0 is first byte NOT to record we want to record length-1-j0, <a name="docC094"> length-1-j0=23 is last byte to record. add one get end0, first byte NOT to record. Code line historyArr[hA++]=oneLine; record current oneLine value to historyArr[]. hA++ auto increase by one. Allow next history record not to erase the current record. <a name="docC095"> onePP=matchParenthesis(historyArr[2]); if(typeof(onePP)=='string')return onePP; Above code line update parenthesis pair matching table onePP. If see error, stop program. 2013-01-10-14-02 here
<a name="docC096"> The order of operation for logical operators is at docA021 Evaluate negations first. Code blow evaluate negation first. ~(P∨Q) iter0=0; m0=-1; while((m0=oneLine.indexOf('~',m0+1))>=0) { iter0++;if(iter0>2000){alert('iter0='+iter0);break;} m1=upper26.indexOf(oneLine.charAt(m0+1)); if(m1<0)continue; //if(m0>=0&&m1>=0) //this is useless a201190840 { old0='~'+oneLine.charAt(m0+1); new0=s2f1[0][1]+'{'+oneLine.charAt(m0+1)+'}' oneLine=updateStr(old0,new0,oneLine); } } iter0 prevent infinite loop. <a name="docC097"> Assume input is (~A∧~(P∨Q)) ---eq.A3a parenthesis pair analysis get [[ (~A_~(P_Q)) 01234567890 0 1 5,9, level=0 0,10, level=1 ]] <a name="docC098"> Code m0=oneLine.indexOf('~',m0+1) in oneLine search for '~'. If can not find '~', m0 has value -1 < 0 Now in "(~A_~(P_Q))" 01234567890 0 1 find m0=1 is '~', m0>=0 is true, enter while() loop. <a name="docC099"> There are two different negation cases. First, '~' right side is logic variable. Above example "~A" is this case. Second, '~' right side is '('. Above example "~(P∨Q)" is this case. This code section replace only first case, not second case. //~(P∨Q) <a name="docC100"> Code m1=upper26.indexOf(oneLine.charAt(m0+1)); oneLine.charAt(m0+1) say in oneLine (~A∧~(P∨Q)) ---eq.A3a look for '~' right side byte "A", see whether "A" is in upper26 Recall upper26='ABCDEFGHIJKLMNOPQRSTUVWXYZ' 0123... "A" is in upper26. m1 has value 0. <a name="docC101"> eq.A3a m0=1 is '~', m0>=0 is true, upper26 m1=0 is 'A', m1>=0 is true. Both true, enter //if(m0>=0&&m1>=0) //this is useless a201190840 { old0='~'+oneLine.charAt(m0+1); new0=s2f1[0][1]+'{'+oneLine.charAt(m0+1)+'}' oneLine=updateStr(old0,new0,oneLine); } a201190952 When proofread code find code line if(m0>=0&&m1>=0) is useless m0>=0 is for sure, otherwise can not enter while((m0=oneLine.indexOf('~',m0+1))>=0) m1>=0 is for sure, one line above is if(m1<0)continue;, now not go away, must be m1>=0 a201190959 <a name="docC102"> old0 build '~A', new0 should be 'notP(A)' then in whole equation oneLine, change all old0 to new0. That is change all '~A' to 'notP(A)' User input (~A∧~(P∨Q)) ---eq.A3a become "(notP(A)∧~(P∨Q))" <a name="docC103"> This result has trouble. Because parenthesis pair is function arguments boundary. parenthesis pair is also logic equation group boundary. Two boundary are totally different. To avoid confusion, program change function arguments boundary from '()' to '{}'. <a name="docC104"> Next line is actual code new0=s2f1[0][1]+'{'+oneLine.charAt(m0+1)+'}' Result is "(notP{A}∧~(P∨Q))" Future parenthesis pair analysis, not involve {A}. At final point, program replace all "{}" with "()" return to correct form function equation. Operator '~' to function name 'notP' replacement, use next code lines. s2f1[0]=['~', 'notP'] s2f1[0][1]='notP'; new0='notP{A}'; <a name="docC105"> oneLine=updateStr(old0,new0,oneLine); updateStr() is a function, in third argument oneLine replace all old0 with new0. In above example oneLine="(~A∧~(P∨Q))" //---eq.A3a old0="~A" new0="notP{A}" After replacement, get oneLine="(notP{A}∧~(P∨Q))" 2013-01-10-14-49 stop
<a name="docC106"> 2013-01-10-16-34 start Each time oneLine change value, must update parenthesis pair matching array. Before this third change/update. Program record history array first three value with explanation. historyArr[0]+=' ; user input'; historyArr[1]+=' ; del blanks' historyArr[2]+=' ; program use' historyArr[hA++]=oneLine ; //update equation onePP=matchParenthesis(historyArr[3]); if(typeof(onePP)=='string')return onePP; <a name="docC107"> historyArr[0] is user input historyArr[1] is del blanks actually it is result of 21 replacement. For short note, write only "del blanks". Next is to remove outer most redundant '()' pair. After these changes get historyArr[2]. historyArr[2] is program use equation. Code line onePP=matchParenthesis(historyArr[3]); build new parenthesis pair matching array onePP. if(typeof(onePP)=='string')return onePP; If error occur, stop program. For example, read document line. 2013-01-10-16-45 stop
<a name="docC108"> 2013-01-11-19-00 start Assume input equation is (~A∧~P∨~Q→~R∨B∧C) ---eq.A4a This equation has ambiguity. Because ~P, ~Q, ~R, B have operator at their both side. It is possible to group in several different ways. logictt2.htm accept ambiguous equation and group according to Order of Operation for Logical Operators <a name="docC109"> For input (~A∧~P∨~Q→~R∨B∧C) ---eq.A4a Evaluate negations first, input equation change to next. oneLine= // next line ---eq.A4b (notP{A}∧notP{P}∨notP{Q}→notP{R}∨B∧C) Unicode '∧', '∨', '→' are wider. change to all ascii bytes, match ruler (notP{A}_notP{P}_notP{Q}_notP{R}_B_C) 0123456789012345678901234567890123456 0 1 2 3333333 <a name="docC110"> iter0=0; var lenPP=onePP.length; var oneArr=new Array(lenPP); var oneL1,oneL2,oneL3; oneArr=updateArr(oneLine); var newLvl0=[]; var uChar=[[-1,'☺',-1]]; <a name="docC111"> For input equation // next line ---eq.A4b (notP{A}∧notP{P}∨notP{Q}→notP{R}∨B∧C) above red color variables have the following values oneArr= 1,36,notP{A}∧notP{P}∨notP{Q}→notP{R}∨B∧C onePP= 0,36,0 lenPP=1 <a name="docC112"> "onePP"=oneLine Parenthesis Pair result. For input // next line ---eq.A4b (notP{A}∧notP{P}∨notP{Q}→notP{R}∨B∧C) onePP=[0,36,0] It say '(' is at ruler 0th location. and ')' is at ruler 36th location. Blue 0 say this "()" is level zero, no other "()" in it. "onePP" information is not complete. Because what string within "()" ? No record. <a name="docC113"> Variable oneArr make up the missing data. oneArr= //red, blue, purple 3 elements [1,36,'notP{A}∧notP{P}∨notP{Q}→notP{R}∨B∧C'] '1' say start from ruler location '1' we have level zero string. At ruler location '36', it is first byte NOT belong to level zero string. This string is 'notP{A}∧notP{P}∨notP{Q}→notP{R}∨B∧C' <a name="docC114"> (notP{A}_notP{P}_notP{Q}_notP{R}_B_C) 0123456789012345678901234567890123456 0 1 2 3333333 Here, compare onePP with oneArr onePP =[0,36,0] oneArr=[1,36,'level zero string'] onePP first entry is 0, '(' location. oneArr first entry is 1, blue 'n' is first byte belong to evel zero string. Second entry, both onePP and oneArr use 36. Because 36 is ')' location, because ')' is first byte not belong to equation. oneArr third entry 'notP{A}∧notP{P}∨notP{Q}→notP{R}∨B∧C' record logic equation, which onePP missed. <a name="docC115"> oneArr=[1,36,'level zero string'] let oneL1 be 'level zero string'. Program will slice oneL1 later. oneL1= 'notP{A}∧notP{P}∨notP{Q}→notP{R}∨B∧C' Program must be able to re-group user supplied ambiguous equation. Negation has first priority (priority 0), earlier code convert "~A" to "notP(A)". Code value: old0="~A" and new0="notP(A)". ∨ and ∧ have second priority (priority 1). → and ↔ have third priority (priority 2). <a name="docC116"> For oneL1= 'notP{A}∧notP{P}∨notP{Q}→notP{R}∨B∧C' program slice oneL1 and save to oneL2. oneL2 find out second priority (priority 1) and third priority (priority 2) operators. oneL2= ['notP{A}∧notP{P}∨notP{Q}', '→', 'notP{R}∨B∧C'] <a name="docC117"> Above/below are three elements in array. Program convert second priority (priority 1) symbolic equation to function equation and record in oneL3. oneL3= ['PiorQ{PandQ{notP{A},notP{P}},notP{Q}}', '→', 'PandQ{PiorQ{notP{R},B},C}'] //why onePP, oneArr have just one line? //I need deep level example. 2013-01-11-19-55 stop <a name="docC118"> Build deep level example 59 a201112028 //---eq.59a (((~A∧(~P∨(~Q→~R)))∨((B∧C)↔P))→((Q∨R)∧(Q∨A))) output confirmed with logicmr2.htm (((~A&(~Pv(~Q>~R)))v((B&C)=P))>((QvR)&(QvA))) and made code correction at "a201112017" <a name="docC119"> 2013-01-12-08-34 start Above example (~A∧~P∨~Q→~R∨B∧C) ---eq.A4a parenthesis is trivial. If use deep level example //next line ---eq.59a (((~A∧(~P∨(~Q→~R)))∨((B∧C)↔P))→((Q∨R)∧(Q∨A))) get the following data. [[ oneLine= //equation ruler ((notP{A}∧(notP{P}∨(notP{Q}→notP{R})))∨((B∧C)↔P))→((Q∨R)∧(Q∨A)) <a name="docC120"> oneArr= //eqn. bgn, eqn. end, bgn to end eqn 20,35,notP{Q}→notP{R} 41,44,B∧C 52,55,Q∨R 58,61,Q∨A 11,36,notP{P}∨(notP{Q}→notP{R}) 40,47,(B∧C)↔P 51,62,(Q∨R)∧(Q∨A) 2,37,notP{A}∧(notP{P}∨(notP{Q}→notP{R})) 1,48,(notP{A}∧(notP{P}∨(notP{Q}→notP{R})))∨((B∧C)↔P) <a name="docC121"> onePP= //'(' location, ')' location, level number 19,35,0 40,44,0 51,55,0 57,61,0 10,36,1 39,47,1 50,62,1 1,37,2 0,48,3 <a name="docC122"> lenPP=9 //onePP[] has nine elements. uChar= -1,☺,-1 ]] uChar=[[-1,☺,-1]] is initial value, define uChar[] later. 2013-01-12-08-40 stop
<a name="docC123"> 2013-01-12-10-05 start while(1) { In while(BooleanValue), program run through while loop body if BooleanValue is true, otherwise while loop body code ignored. <a name="docC124"> BooleanValue has true or false two possibilities. In while(1), 1 is not true and not false. javascript treat non-zero integer as true, and zero as false. Then write while(1), or while(2) or while(3) all be same. They are all while(true) and all be infinite loop. We can not run a loop infinite long. Inside infinite loop must set up condition to break from infinite loop. 2013-01-12-10-20 stop
<a name="docC125">KEY: reduce () to {} 2013-01-12-11-57 start A logic equation may have multiple parenthesis pair level. logictt2.htm convert only level zero from symbolic to function equation. Before convert, level zero part_of_equation contain operator ∨,∧,→,↔ etc. No function() that is no PandQ(A,B) etc. After convert, level zero part_of_equation contain function equation, that is it contains PandQ(A,B) etc. No operator ∨,∧,→,↔ etc. <a name="docC126"> After convert, program change level 0 boundary from '(' and ')' to '{' and '}'. In next parenthesis pair analysis old level 0 disappear, old level 1 become new level 0. Program continue convert level 0 part_of_equation until whole equation no '(' and no ')'. This step, convert from symbolic to code equation is done. 2013-01-12-12-08 here <a name="docC127"> Run example 59, input equation is //---eq.59a (((~A∧(~P∨(~Q→~R)))∨((B∧C)↔P))→((Q∨R)∧(Q∨A))) Above is Unicode, below is ascii code (((~A_(~P_(~Q_~R)))_((B_C)_P))_((Q_R)_(Q_A))) 012345678901234567890123456789012345678901234 0 1 2 3 4 10,16, level=0 21,25, level=0 32,36, level=0 38,42, level=0 6,17, level=1 20,28, level=1 31,43, level=1 2,18, level=2 1,29, level=3 0,44, level=4 <a name="docC128"> Above ascii code line not show up in logictt2.htm , because program change negation first, get next line ((notP{A}∧(notP{P}∨(notP{Q}→notP{R})))∨((B∧C)↔P))→((Q∨R)∧(Q∨A)) Above is Unicode, below is ascii code ((notP{A}_(notP{P}_(notP{Q}_notP{R})))_((B_C)_P))_((Q_R)_(Q_A)) 01234567890123456789012345678901234567890123456789012345678901234567890 0 1 12 3 3 4 4 55 5 5 66 Red parenthesis is level 0 boundary. <a name="docC129"> onePP=oneLine Parenthesis Pair result. onePP= 19,35,0 40,44,0 51,55,0 57,61,0 10,36,1 39,47,1 50,62,1 1,37,2 0,48,3 <a name="docC130"> After done first iteration level 0, get next ((notP{A}∧(notP{P}∨{PiftQ{notP{Q},notP{R}}}))∨({PandQ{B,C}}↔P))→({PiorQ{Q,R}}∧{PiorQ{Q,A}}) Above is Unicode, below is ascii code Below has NEW level 0, marked red. Underline '_' is Unicode operator. ((notP{A}_(notP{P}_{PiftQ{notP{Q},notP{R}}}))_({PandQ{B,C}}_P))_({PiorQ{Q,R}}_{PiorQ{Q,A}}) 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 0 1 2 3 4 4 4 5 66 6 7 8 9 <a name="docC131"> onePP= 10,43,0 46,61,0 64,90,0 1,44,1 0,62,2 This remove level 0 process continue. Please run example 59 and go to Box08 for detail. (Must choose Box08 debug [v] ON) <a name="docC132"> Because logictt2.htm convert only level zero from symbolic to function equation. onePP[] level index is very important. Next five red number are onePP[] level index onePP= //onePP[*][2] is level index 10,43,0 46,61,0 64,90,0 1,44,1 0,62,2 <a name="docC133"> onePP and oneArr are twins, new level zero part_of_equation are next red string. Program convert symbolic to code equation for next red string right below here. oneArr= //oneArr[*][2] is part_of_equation 11,43,notP{P}∨{PiftQ{notP{Q},notP{R}}} 47,61,{PandQ{B,C}}↔P 65,90,{PiorQ{Q,R}}∧{PiorQ{Q,A}} 2,44,notP{A}∧(notP{P}∨{PiftQ{notP{Q},notP{R}}}) 1,62,(notP{A}∧(notP{P}∨{PiftQ{notP{Q},notP{R}}}))∨({PandQ{B,C}}↔P) First three lines red string no '()' . Line 4/5 black string has '()' in it. <a name="docC134"> Above explain why next while loop use (onePP[i0][2]==0) as T/F condition. If it is level zero, convert, otherwise stop. Next while(onePP[i0][2]==0) is second while() loop, it is inside first while(1) loop. i0=0; while(onePP[i0][2]==0) { oneL1=oneArr[i0][2] uChar=[]; uC=0; <a name="docC135"> Code oneL1=oneArr[i0][2] save new level zero part_of_equation to variable oneL1 and begin convert to code equation. For example, change from notP{P}∨{PiftQ{notP{Q},notP{R}}} to PiorQ{notP{P},{PiftQ{notP{Q},notP{R}}}} This change record at 'twist code' 2013-01-12-13-22 stop <a name="docC136"> 2013-01-12-15-08 start oneL1 record one piece level 0 symbol equation. uCode[*][0] record this code piece ∨,∧,→,↔ operator location. uCode[*][1] what operator it is? uCode[*][2] what priority it has? <a name="docC137"> If oneL1="notP{Q}→notP{R}" 012345678901234 uChar=[[7,→,2]] At 7th place has '→', priority 2 //priority 0 is '~' //first priority //priority 1 is '∨,∧' //second priority //priority 2 is '→,↔' //third priority Above oneL1 is simple. <a name="docC138"> Next oneL1 is real working example. If oneL1="notP{A}∧notP{P}∨notP{Q}→notP{R}∨B∧C" in ascii="notP{A}_notP{P}_notP{Q}→notP{R}_B_C" 01234567890123456789012345678901234 0 1 2 3 uChar= [[7,'∧',1], [15,'∨',1], [23,'→',2], [31,'∨',1], [33,'∧',1]] <a name="docC139"> Program see priority 2 line, split oneL1 to smaller sections. from "notP{A}∧notP{P}∨notP{Q}→notP{R}∨B∧C" to "notP{A}∧notP{P}∨notP{Q}" "→" "notP{R}∨B∧C" <a name="docC140"> Program process priority 1 line first notP{A}notP{P}notP{Q} become PiorQ{PandQ{notP{A},notP{P}},notP{Q}} and "notP{R}BC" //red left (first) PandQ{PiorQ{notP{R},B},C} //red inner Because "∨" and "∧" have same priority. Order of Operation for Logical Operators say that if no parenthesis present in equation work left to right. <a name="docC141"> Above red are first in symbolic equation. Above red are inner in function equation. Above blue are second in symbolic equation. Above blue are outer in function equation. Professor Michael Rieppel program do not allow ambiguity, Rieppel code logicmr2.htm do not have the worry LiuHH has ! <a name="docC142"> Finally process priority 2 operator "→" "PiorQ{PandQ{notP{A},notP{P}},notP{Q}}PandQ{PiorQ{notP{R},B},C} become {PiftQ{PiorQ{PandQ{notP{A},notP{P}},notP{Q}},PandQ{PiorQ{notP{R},B},C}}} 2013-01-12-16-07 here 2013-02-24-10-24 add start Chicken first? egg first? "change all '()' to '{}'" occur first? "highest level operator process" done first? Program design is "change all '()' to '{}'" first and "highest level operator process" done second. change all '()' to '{}' occur before highest level operator process. Enter if(oneLine.indexOf('(')<0) { //do highest level operator conversion. oneLine=updateAnd(oneLine); ... } 2013-02-24-10-29 add stop
<a name="docC143"> for(j2=0;j2<oneL1.length;j2++) { if(ubyte.indexOf(oneL1.charAt(j2))>=0) { if(oneL1.charAt(j2)=='~') return 'sym2fun1(arg1) error 21. In\n' +oneL1+'\n' +'find \'~\' which is unexpected.\n' +'Programming error. a112111441' uChar[uC]=[]; uChar[uC][0]=j2; uChar[uC][1]=oneL1.charAt(j2); if(oneL1.charAt(j2)=='∨' //OR ||oneL1.charAt(j2)=='⊻' //XOR ||oneL1.charAt(j2)=='∧' //AND ||oneL1.charAt(j2)=='|' //NAND a201191521 ||oneL1.charAt(j2)=='⊽' //NOR add '|', '⊽' ) uChar[uC][2]=1; else uChar[uC][2]=2; uC++; } //if(ubyte.indexOf(oneL1.charAt(j2))>=0) } //for(j2=0;j2<oneL1.length;j2++) <a name="docC144"> Assume oneL1="notP{A}∧notP{P}∨notP{Q}" There are two operators in it "∧" and "∨" This oneL1 has 23 characters. oneL1.length=23. for(j2=0;j2<oneL1.length;j2++) j2 start from 0, step over oneL1. ubyte="~∨⊻∧→←↔⇒⇐⇔|⊽乙人丩力匕卜厂又"; Each of these operator bytes match a function name at s2f1[][] <a name="docC145"> Code line if(ubyte.indexOf(oneL1.charAt(j2))>=0) say in ubyte string find whether there is match with oneL1.charAt(j2). Since j2 change from 0 to 23. oneL1.charAt(j2) has value 'n', 'o', ... 'A', '}', '∧' ... Recall oneL1="notP{A}∧notP{P}∨notP{Q}" <a name="docC146"> When j2 step on '' (j2=7), this byte DOES occur in ubyte="~∨⊻→←↔⇒⇐⇔|⊽乙人丩力匕卜厂又"; 0123456789... ubyte.indexOf(oneL1.charAt(j2)) has value 3 which is greater than 0 if condition if(ubyte.indexOf(oneL1.charAt(j2))>=0) become true. Enter if() body. <a name="docC147"> First check whether this operator is negation '~', if yes, programming error and return (stop). Normally, this error do not occur. Continue code below to build uChar[][] array. In example oneL1="notP{A}∧notP{P}∨notP{Q}" There are two operators "∧", "∨". uChar should have next structure uChar=[[7,'∧',1], [15,'∨',1]] <a name="docC148"> [7,'∧',1] say in "notP{A}∧notP{P}∨notP{Q}" 7th character location has '∧', its priority is 1. [15,∨,1] has similar interpretation. <a name="docC149"> Next code build above uChar array. uChar[uC]=[]; tell javascript that uChar[uC] is an array. If uC=0, uChar[0] is an array. If uC=1, uChar[1] is an array. etc. After declare uChar[uC] be an array, then uChar[0][0], uChar[0][1], uChar[0][2] etc are legal. <a name="docC150"> When uC=0 uChar[uC]=uChar[0]=[7,'∧',1] uChar[uC][0]=j2; record 7 in [7,'∧',1] uChar[uC][1]=oneL1.charAt(j2); record '∧' in [7,'∧',1] if(oneL1.charAt(j2)=='∨' //OR ||oneL1.charAt(j2)=='⊻' //XOR ||oneL1.charAt(j2)=='∧' //AND ||oneL1.charAt(j2)=='|' //NAND a201191521 ||oneL1.charAt(j2)=='⊽' //NOR add '|', '⊽' ) uChar[uC][2]=1; else uChar[uC][2]=2; record priority 1 in [7,'∧',1] <a name="docC151"> If input equation is example 37 //---eq.37b (~A∧~P∨~Q→~R∨B∧C)↔(P→(Q∨R)∧(Q∨A)) The left half (~A∧~P∨~Q→~R∨B∧C) ---eq.A4a Change negation first, get // next line ---eq.A4b notP{A}∧notP{P}∨notP{Q}→notP{R}∨B∧C has next uChar[][] value //equation ruler uChar= 7,∧,1 15,∨,1 23,→,2 31,∨,1 33,∧,1 <a name="docC152"> They are created right here (red line above) 23,→,2 has priority 2. Program run priority 1 first and run priority 2 second. 2013-01-12-17-23 stop
<a name="docC153"> 2013-01-12-18-25 start logictt2.htm program is sensitive to '(' and ')'. After done MOST convert from symbol equation to function equation, all '(', and ')' change to '{' and '}'. Please see chicken first? egg first? If input equation level 0 section has operator in it. Above for(j2=0;j2<oneL1.length;j2++) loop build uChar[][] table. Later code will change oneL1 boundary from '(', and ')' to '{' and '}' <a name="docC154"> If input equation level 0 section do not have operator in it. Above for(j2) loop do not build uChar[][] table. Later code will not change boundary from '(', and ')' to '{' and '}', Then later parenthesis pair matching analysis get trouble. <a name="docC155"> What is the case an equation level 0 part not contain operator? Example 1 (~(P∨Q))↔((~P)∧(~Q)) ---eq.01a has this case. Above equation level 0 are (P∨Q) and (~P) and (~Q). Program read input, first thing to do is change all negation ~P, ~Q to notP(P), notP(Q) <a name="docC156"> Input (~(P∨Q))↔((~P)∧(~Q)) ---eq.01a enter analysis with the form (~(P∨Q))↔((notP{P})∧(notP{Q})) ---eq.01b This equation level 0 partial equation are (P∨Q) and (notP{P}) and (notP{Q}). Both (notP{P}) and (notP{Q}) do not have any of ∨,∧,→,↔. Next code take care this special case first. <a name="docC157"> if(uC==0&&i0<oneArr.length) //a112171156 { oneLine=oneLine.substring(0,oneArr[i0][0]-1) +'{'+oneArr[i0][2]+'}' +oneLine.substring(oneArr[i0][1]+1,oneLine.length) } <a name="docC158"> i0 is oneArr[i0] index parameter. See [[ while(1) //a201120848 use { i0=0; while(onePP[i0][2]==0) { oneL1=oneArr[i0][2] ..... ]] <a name="docC159"> Code line if(uC==0&&i0<oneArr.length) say, if not find any operator (uC==0) (uC is uChar.length, uChar[uC]=[];) i0<oneArr.length say oneArr[] still not finish. It is "notP{Q}". Change from "(notP{Q})" to "{notP{Q}}" <a name="docC160"> If input is (~(P∨Q))↔((~P)∧(~Q)) ---eq.01a change to (~(P∨Q))↔((notP{P})∧(notP{Q})) We need care no operator red section below oneArr= 3,6,P∨Q 11,18,notP{P} 21,28,notP{Q} 1,7,~(P∨Q) 10,29,(notP{P})∧(notP{Q}) for (notP{P}) 11 point to 'n' [10 point to '('] 18 point to ')' <a name="docC161"> To see ruler scale, write Unicode (~(P∨Q))↔((notP{P})∧(notP{Q})) ---eq.01b as ascii code below (~(PvQ))↔((notP{P})^(notP{Q})) 012345678901234567890123456789 0 1 1 2 Work is change red () to {} docC162 change no operator level 0 () to {} docC309 change has operator level 0 () to {} <a name="docC162"> Code line oneLine=oneLine.substring(0,oneArr[i0][0]-1) +'{'+oneArr[i0][2]+'}' +oneLine.substring(oneArr[i0][1]+1,oneLine.length) has following numerical version //has real value oneLine=oneLine.substring(0,11-1) //'(~(PvQ))↔(' +'{'+oneArr[i0][2]+'}' //+'{'+'notP{P}'+'}' +oneLine.substring(18+1,oneLine.length) //+'∧(notP{Q}))' <a name="docC163"> 11,18 and notP{P} come from earlier 11,18,notP{P} "-1" in "11-1" drop 10 (, replace with '{'. "+1" in "18+1" drop 18 ), replace with '}'. String together '(~(PvQ))↔(' + '{'+'notP{P}'+'}' + '∧(notP{Q}))' get '(~(PvQ))↔({notP{P}}∧(notP{Q}))' Above is after replacement, below is before. '(~(P∨Q))↔((notP{P})∧(notP{Q}))' Alert '{notP{P}}' no operator in it. (notP{Q}) do the same procedure. 2013-01-12-19-26 stop
<a name="docC164"> 2013-01-13-13-29 start logictt2.htm allow user input ambiguous equation, there are extra code work to do. The following is the extra work. Here use example 38 first line equation ~A∧~B∨~C→~D∨E∧F↔G∨~H∧I ---eq.38a as example. This equation has nine logic variable A,B,C,D,E,F,G,H,I five priority 0 negation '~' operator six priority 1 AND/OR '∨,∧' operator two priority 2 ift/iff '→,↔' operator Certainly, this equation is fabricated for testing logictt2.htm order of operation code. <a name="docC165"> According to LogicTeacher.pdf ~A∧~B∨~C→~D∨E∧F↔G∨~H∧I ---eq.38a should change to next (((~A∧~B)∨~C)→((~D∨E)∧F))↔((G∨~H)∧I) ---eq.38b Input is example 38 line one ~A∧~B∨~C→~D∨E∧F↔G∨~H∧I ---eq.38a Program change negation first, get (notP{A}∧notP{B}∨notP{C}→notP{D}∨E∧F↔G∨notP{H}∧I) ---eq.38c <a name="docC166"> It has the following scale (notP{A}_notP{B}_notP{C}notP{D}_E_F↔G_notP{H}_I) 0123456789012345678901234567890123456789012345678 0 1 2 3 4 4 Whole equation is in level zero, only one pair outer '()', no more. <a name="docC167"> oneArr= //record level zero equation 1,48,notP{A}∧notP{B}∨notP{C}→notP{D}∨E∧F↔G∨notP{H}∧I onePP=oneLine Parenthesis Pair result= 0,48,0 oneArr and onePP use above equation, has '()' uChar use next equation, delete boundary '()' notP{A}_notP{B}_notP{C}notP{D}_E_F↔G_notP{H}_I 012345678901234567890123456789012345678901234567 0 1 2 3 4 4 Above equation cut at priority 2 '→' and '↔'. Divide whole equation to red/blue/black three sections. <a name="docC168"> From input equation, program build uChar= [[7,'∧',1], [15,'∨',1], [23,'→',2], //cut at priority 2 [31,'∨',1], [33,'∧',1], [35,'↔',2], //cut at priority 2 [37,'∨',1], [45,'∧',1]] Next code do the re-grouping. <a name="docC169"> Liu,Hsinhan consider the following code is the core of logictt2.htm 2013-01-13-14-17 here oneL2=[]; oL2=0; bgn2=0; end2=oneL1.length; for(j0=0;j0<uChar.length;j0++) { if(uChar[j0][2]==2) { end2=uChar[j0][0]; oneL2[oL2++]=oneL1.substring(bgn2,end2) oneL2[oL2++]=oneL1.substring(end2,end2+1) bgn2=end2+1; } //if(uChar[j0][2]==2) } //for(j0=0;j0<uChar.length;j0++) <a name="docC170"> oneL1 is next //'☺' is NOT part of equation notP{A}∧notP{B}∨notP{C}→notP{D}∨E∧F↔G∨notP{H}∧I☺ bgn2 initialize to zero, point to 0 at 'n' end2 initialize to oneL1.length, point to 47 at '☺' right to whole equation. Above code cut oneL1 to five pieces and store to array <a name="docC171"> oneL2[]= ['notP{A}∧notP{B}∨notP{C}', //left section '→', //cutting point 'notP{D}∨E∧F', //middle section '↔', //cutting point 'G∨notP{H}∧I'] //right section oL2 is array oneL2[] counter. oneL2[oL2++] <a name="docC172"> Why cut this way? Operator '∧,∨' have priority 1 Operator '→,↔' have priority 2 Program convert left/middle/right section equation from symbolic to function first. After this, convert priority 2 operator equation 'left→middle↔right'. Confuse? what is left,middle,right ? If input is ~A∧~B∨~C→~D∨E∧F↔G∨~H∧I ---eq.38a 'left→middle↔right' is short for next line '{PiorQ{PandQ{notP{A},notP{B}},notP{C}}}→{PandQ{PiorQ{notP{D},E},F}}↔{PandQ{PiorQ{G,notP{H}},I}}' <a name="docC173"> j0=0 to 7, step over uChar. uChar= [[7,'∧',1], //uChar[0] [15,'∨',1], //uChar[1] [23,'→',2], //uChar[2] [31,'∨',1], //uChar[3] [33,'∧',1], //uChar[4] [35,'↔',2], //uChar[5] [37,'∨',1], //uChar[6] [45,'∧',1]] //uChar[7] uChar[0]=[7,'∧',1] uChar[0][0]=7 uChar[0][1]='∧' uChar[0][2]=1 <a name="docC174"> Code line if(uChar[j0][2]==2) say when j0 step over uChar[][], if see priority 2 line, enter if() body do work. Re-display equation notP{A}_notP{B}_notP{C}notP{D}_E_F↔G_notP{H}_I 012345678901234567890123456789012345678901234567 0 1 2 2 3 4 4 <a name="docC175"> Assume work at left one third (red). if(uChar[j0][2]==2) match [23,'→',2], //uChar[2], j0=2 Blue 2 and red 2 are different. Because next match will be [35,'↔',2], //uChar[5], j0=5 Red 2 say priority 2 operator "→,↔" Blue 2 say uChar[j0] or uChar[2] Blue 5 say uChar[j0] or uChar[5] <a name="docC176"> Code line end2=uChar[j0][0]; define end2. end2=uChar[j0][0]=uChar[2][0]=23 Here, not change bgn2, bgn2 is still 0 Above re-display equation from 0 to 23 is red color left section. 0 is first byte of selected section. 23 is first byte of out-range section. <a name="docC177"> Code line oneL2[oL2++]=oneL1.substring(bgn2,end2) record 'notP{A}_notP{B}_notP{C}' to oneL2[oL2] and immediately increase counter by one oL2++, so that next record do not wipe out current record by accident. <a name="docC178"> Code line oneL2[oL2++]=oneL1.substring(end2,end2+1) record '' to oneL2[oL2] and immediately increase counter by one oL2++. (end2,end2+1) has begin at end2, and end at end2+1. Record character = (end2+1)-end2 = 1 character '' <a name="docC179"> Code line bgn2=end2+1; update bgn2 to end2+1=23+1=24 24 point to left end of blue section. Second iteration do same thing as above and record up to '↔'. <a name="docC180"> Re-display equation right end black section 'G_notP{H}_I' do not have right side priority 2 operator, no third iteration if(uChar[j0][2]==2) to do the recording work. Right end black section 'G_notP{H}_I' will be recorded after exit for(j0=0;j0<uChar.length;j0++) loop.
<a name="docC181"> Next code continue from above code. Next code exit from for(j0=0;j0<uChar.length;j0++) if(oL2>1) bgn2=end2+1; end2=oneL1.length; oneL2[oL2++]=oneL1.substring(bgn2,end2) Above code record Re-display equation right end black section 'G_notP{H}_I' to oneL2[oL2++]. Here '++' in 'oL2++' is necessary, if increase oL2 by one, oL2 new value is same as oneL2[] number of elements value. If equation no operator in it, oneL2 has one element. bgn2 initialized to 0 which is just right. Otherwise define bgn2 to be end2+1. In above example new bgn2=end2+1 is 36. '+1' cross '↔'. How about new end2 ? easy, last section end point must be oneL1.length. <a name="docC182"> Start work, input string is oneL1= //a string variable 'notP{A}∧notP{B}∨notP{C}→notP{D}∨E∧F↔G∨notP{H}∧I' At this point, we get oneL2= //an array_of_string variable ['notP{A}∧notP{B}∨notP{C}', '→', 'notP{D}∨E∧F', '↔', 'G∨notP{H}∧I'] 2013-01-13-15-26 stop
<a name="docC183"> 2013-01-13-17-33 start Above illustrate what is oneL1 and oneL2. Below is oneL3. If continue above example, oneL3 has next value oneL3= //an array_of_string variable ['PiorQ{PandQ{notP{A},notP{B}},notP{C}}', '→', 'PandQ{PiorQ{notP{D},E},F}', '↔', 'PandQ{PiorQ{G,notP{H}},I}'] oneL2 has operator equation. oneL3 has function equation. Change from operator equation to function equation is main goal. <a name="docC184"> Code below change from oneL2 to oneL3. oneL3=[]; for(j0=0;j0<oneL2.length;j0++) { if(j0%2)oneL3[j0]=oneL2[j0] else oneL3[j0]=updateAnd(oneL2[j0]) } //for(j0=0;j0<oneL2.length;j0++) <a name="docC185"> Code oneL3=[]; tell javascript that oneL3 is an array. After this point, oneL3[0], oneL3[1] can be used. Code for(j0=0;j0<oneL2.length;j0++) say j0 start from 0, step over oneL2 until j0=oneL2.length-1. We need process oneL2. Review above oneL2 and oneL3 value, it is clear that <a name="docC186"> if j0=1, oneL3[1]=oneL2[1]='→', if j0=3, oneL3[3]=oneL2[3]='↔', value do not change. In general, for j0=1,3,5,7,9 ... odd number, oneL3[odd]=oneL2[odd]='→' or '↔' Divide an integer by 2, its remainder determine this integer is even or odd. All odd number has remainder 1. All even number has remainder 0. if() evaluation see non-zero be true. if() evaluation see zero be false. <a name="docC187"> '%' is a remainder operator. integerA%integerB = remainder value. 1%2=3%2=5%2=1 2%2=4%2=6%2=0 Code line if(j0%2)oneL3[j0]=oneL2[j0] say if(j0 is odd) copy oneL2[j0] to oneL3[j0] <a name="docC188"> Code line else oneL3[j0]=updateAnd(oneL2[j0]) say otherwise send oneL2[j0] to function updateAnd() and save process result to oneL3[j0]. Clearly function updateAnd() change from 'notP{A}∧notP{B}∨notP{C}' to 'PiorQ{PandQ{notP{A},notP{B}},notP{C}}' Discuss at function updateAnd() document. 2013-01-13-18-08 here
<a name="docC189"> Up to here, we have oneL3= //an array_of_string variable ['PiorQ{PandQ{notP{A},notP{B}},notP{C}}', '→', 'PandQ{PiorQ{notP{D},E},F}', '↔', 'PandQ{PiorQ{G,notP{H}},I}'] These five strings is actually one string. Next code string them together save as iffift1. Process iffift1 to get iffift2 <a name="docC190"> iffift1='' for(j0=0;j0<oneL3.length;j0++) { iffift1+=oneL3[j0] } if(oneL2.length>1) //a201200444 if()else iffift2=updateAnd(iffift1); else iffift2=iffift1; Above code for(j0=0;j0<oneL3.length;j0++){body} Collect all pieces from oneL3[] and save to iffift1. <a name="docC191"> For above oneL3, iffift1= PiorQ{PandQ{notP{A},notP{B}},notP{C}}→PandQ{PiorQ{notP{D},E},F}↔PandQ{PiorQ{G,notP{H}},I} call iffift2=updateAnd(iffift1) get iffift2= PiffQ{PiftQ{PiorQ{PandQ{notP{A},notP{B}},notP{C}},PandQ{PiorQ{notP{D},E},F}},PandQ{PiorQ{G,notP{H}},I}} iffift1, iffift2 are input level 0 partial equation. If level 0 has "∨ ∧", no "→ ↔", then oneL2[], oneL3[] has just one element. If level 0 has "∨ ∧" and "→ ↔", oneL2[], oneL3[] has more than two elements code if(oneL2.length>1)iffift2=updateAnd(iffift1); else iffift2=iffift1; say: //a201201325 purple if level 0 has "∨,∧,→,↔" call updateAnd(). This call do not take care of all "→ ↔", Equation may change all '()' to '{}' before convert highest level "→ ↔" to PiftQ,PiffQ. Please see chicken first? egg first? When no more '(', program call updateAnd() take care of outer most "→ ↔" at a201192105 <a name="docC192"> If input has only priority 1 operator '∨,∧', function updateAnd() will convert from symbolic equation to function equation. If input has only priority 2 operator '→,↔', function updateAnd() will convert from symbolic equation to function equation. If input has mix of priority 1 and priority 2 operator '∨,∧,→,↔', function updateAnd() send error message and stop work. Example 36 line2: (A∨B)→(C↔D)∧(E∨G) this type error. This is why here priority 2 operator '→,↔' also use function updateAnd() logictt2 not use updateift() 2013-01-13-18-27 here
<a name="docC193"> newLvl0[i0]=iffift2; i0++; if(i0>=onePP.length)break; } //while(onePP[i0][2]==0) Above process from old level 0 strings to new level 0 string newLvl0[]. One logic equation may contain several level 0 string, need an array newLvl0[] to keep the result. <a name="docC194"> Example ~A∧~B∨~C→~D∨E∧F↔G∨~H∧I ---eq.38a whole equation is level 0, let logictt2.htm to re-group. If input is (((~A∧~B)∨~C)→((~D∨E)∧F))↔((G∨~H)∧I) ---eq.38b both are identical, the second form has three level 0 string '(~A∧~B)', '(~D∨E)', '(G∨~H)' <a name="docC195"> If input second form, newLvl0[] is an array of three elements. Code line i0++; say in level 0 array onePP advance to next string. Code line if(i0>=onePP.length)break; say if level 0 array all done, then break from while(onePP[i0][2]==0) loop Remind: onePP[i0][2] record i0 th string level number. <a name="docC196"> logictt2.htm process ONLY level 0 string. What happen to level 1? What happen to level 2? After done level zero. Code change level 0 boundary from '(' and ')' to '{' and '}' . Re-do parenthesis pair analysis, old level 1 will change to new level 0. Continue this way, until all '(' and ')' disappear then job is done. more nearly done 2013-01-13-18-46 stop
<a name="docC197"> 2013-01-13-20-30 start Next code assemble new oneLine equation. This process change level 0 boundary from '(' and ')' to '{' and '}'. Let old level 1 become new level 0. bgn0=0; end0=oneArr[0][0]-1 new1Line=''; negP=''; for(j0=0;j0<oneArr.length;j0++) { if(onePP[j0][2]>0)break; <a name="docC198"> Only old level 0 string change to function equation. String outside of bgn0 and end0 are old level 1,2,3 symbolic equation. If input ((~A∧~(B∨C))→((~D∨E)∧F))↔((G∨~H)∧I) ---eq.A5a red string are level 0 . First change negation to notP{*}, get next oneLine= ((notP{A}∧~(B∨C))→((notP{D}∨E)∧F))↔((G∨notP{H})∧I) ---eq.A5b <a name="docC199"> Ruler is next ((notP{A}_~(B_C))_((notP{D}_E)_F))_((G_notP{H})_I) 012345678901234567890123456789012345678901234567890 0 111 2 3 4 5 <a name="docC200"> oneArr= 12,15,B∨C 20,29,notP{D}∨E 37,46,G∨notP{H} 2,16,notP{A}∧~(B∨C) 19,32,(notP{D}∨E)∧F 36,49,(G∨notP{H})∧I 1,33,(notP{A}∧~(B∨C))→((notP{D}∨E)∧F) <a name="docC201"> onePP= 11,15,0 19,29,0 36,46,0 1,16,1 18,32,1 35,49,1 0,33,2 <a name="docC202"> Now target at '~(B_C)' oneArr[0]=[12,15,'B∨C'] oneArr[0][0]=12 oneArr[0][0]-1=12-1=11 11 point to '(' in '~(B_C)' (see ruler above) Code line bgn0=0; end0=oneArr[0][0]-1 and later code +oneLine.substring(bgn0,end0) record '((notP{A}_~' to new oneLine new1Line IF last byte in '((notP{A}_~' is not '~'. Now last byte in '((notP{A}_~' is '~', there is special care. <a name="docC203"> Code line negP=''; set negP to empty string. If input were //use '(B∨C)', not '~(B∨C)' ((~A∧(B∨C))→((~D∨E)∧F))↔((G∨~H)∧I) ---eq.A6a (B∨C) left side no '~', negP='' not change. Now input is //use '~(B∨C)', not '(B∨C)' ((~A∧~(B∨C))→((~D∨E)∧F))↔((G∨~H)∧I) ---eq.A5a (B∨C) left has '~', negP change to 'notP' <a name="docC204"> Code line for(j0=0;j0<oneArr.length;j0++) let j0 scan over oneArr. Code line if(onePP[j0][2]>0)break; say if arrive level 1 string, break from for(j0) loop. Again, logictt2.htm process ONLY level 0 string. more1 more2 2013-01-13-21-11 here
<a name="docC205"> Early code change '~A' to 'notP(A)' at very first step. But not apply to '~(B∨C)' //'~A' no '('; '~(B∨C)' has '('. Next code convert negation of a '(term)' to 'notP(term)' if(oneLine.charAt(end0-1)=='~') { end0--; negP='notP' } <a name="docC206"> Above example has 11 point to '(' in '~(B_C)' end0=oneArr[0][0]-1=12-1=11 oneLine.charAt(end0-1) is oneLine.charAt(11-1) and is '~'. This '~' is part of '(B_C)' if() evaluation if(oneLine.charAt(end0-1)=='~') is true. Carry out command end0--; let level 1 string exclude '~' negP='notP' let (level 0) string add function 'notP' to its left.
<a name="docC207"> Next code assemble new oneLine new1Line+='' +oneLine.substring(bgn0,end0) //+' #1 ' //level 1 and higher +negP //+' #2 ' //+oneLine.substring(end0-2,end0+1)+' #z ' +'{' //+' #3 ' //reduce old level 1 to new level 0 +newLvl0[j0] //+' #4 ' //level 0 partial equation +'}' //+' #5 ' //reduce level negP=''; //a112171600 not allow extend to future <a name="docC208"> negP=''; reset to empty string. { and } let program be able to reduce level. a112171600 correction is realized at later time. Before correction, later level 0 string without '~' still add function name 'notP' to its left. Get error output. Now it is OK. 2013-01-13-21-33 here
<a name="docC209"> bgn0=oneArr[j0][1]+1; if(j0<oneArr.length-1) end0=oneArr[j0+1][0]-1 else break; //<a name="a201141817why"> //j0++; //a201141457use //a201141817 why re-appear? //above j0++ was used when I change //for(j0=0;j0<oneArr.length;j0++) //to while(2). After drop while(2) //I deleted j0++ and program run OK //but now j0++ reappear in //for(j0=0;j0<oneArr.length;j0++) //how j0++ entered? a201141817 why } //for(j0=0;j0<oneArr.length;j0++) <a name="docC210"> Why "bgn0=oneArr[j0][1]+1;"? Why "end0=oneArr[j0+1][0]-1"? Re-visit early example oneLine= ((notP{A}∧~(B∨C))→((notP{D}∨E)∧F))↔((G∨notP{H})∧I) ---eq.A5b Ruler is next ((notP{A}_~(B_C))_((notP{D}_E)_F))_((G_notP{H})_I) 012345678901234567890123456789012345678901234567890 0 1111111 2 3 4 5 <a name="docC211"> Assume we have done red ~(B_C) continue to blue notP{D}_E First recording period is 0123456789012345 Second recording period is 67890123456789 One recording period is new1Line+=... once oneArr= 12,15,B∨C //oneArr[0], j0=0 20,29,notP{D}∨E //oneArr[1], j0=1 ..... onePP= 11,15,0 19,29,0 ..... <a name="docC212"> Above red section is j0=0, blue j0=1. bgn0=oneArr[j0][1]+1; bgn0=oneArr[0][1]+1=15+1=16 Above blue string first byte is 16 Above take care of new section begin. How about new section end? If it is last section, later code record new1Line+='' +oneLine.substring(bgn0,oneLine.length) <a name="docC213"> If it is not last section, define end0 if(j0<oneArr.length-1) end0=oneArr[j0+1][0]-1 end0=oneArr[0+1][0]-1 =oneArr[1][0]-1=20-1=19 Above example has bgn0=16, end0=19, record bytes at 16,17,18 ")_(". Above answered two why. Below build new1Line red,blue,purple once each. new1Line+='' +oneLine.substring(bgn0,end0) +negP +'{' +newLvl0[j0] +'}' <a name="docC214"> in which +oneLine.substring(bgn0,end0) record blue section ')_(', that is 16+17+18 three bytes. 19 th '(' will change to '{' 29 th ')' will change to '}' 'notP{D}_E' will change to 'PiorQ{notP{D},E}' '_' in ')_(' is higher level operator '∨∧→↔' change to ascii '_' for ruler. Here, is end of for(j0=0;j0<oneArr.length;j0++) 2013-01-13-22-10 stop <a name="docC215"> 2013-01-14-13-08 start Review above for(j0) loop for(j0=0;j0<oneArr.length;j0++) { if(onePP[j0][2]>0)break; if(oneLine.charAt(end0-1)=='~') {end0--; negP='notP';} new1Line+='' +oneLine.substring(bgn0,end0) +negP+'{'+newLvl0[j0]+'}'; negP=''; bgn0=oneArr[j0][1]+1; if(j0<oneArr.length-1)end0=oneArr[j0+1][0]-1; else break; } //for(j0=0;j0<oneArr.length;j0++) <a name="docC216"> There are three method to break from for(j0) loop 1. when j0==oneArr.length, violate j0<oneArr.length condition. 2. if(onePP[j0][2]>0)break; 3. if(j0<oneArr.length-1)end0=...; else break; Break method 1 "when j0==oneArr.length" should not occur. If happen, it is code error. The following is Break method 2 and Break method 3 <a name="docC217"> If input ((~A∧~(B∨C))→((~D∨E)∧F))↔((G∨~H)∧I) ---eq.A5a Colored string are level 0 . First change negation to notP{*}, get next oneLine= ((notP{A}∧~(B∨C))→((notP{D}∨E)∧F))↔((G∨notP{H})∧I) ---eq.A5b Ruler is next //right end '_I)' is main concern ((notP{A}_~(B_C))_((notP{D}_E)_F))_((G_notP{H})_I) 012345678901234567890123456789012345678901234567890 0 111 2 3 4 5 This equation break from for(j0) at 2. if(onePP[j0][2]>0)break; <a name="docC218"> Three level 0 strings, for(j0) run three iterations. First iter. red, 0123456789012345 convert to function equation string notP{A}notP{PiorQ{B,C}} only convert level 0 ~(B∨C) . Future replace . Within first iteration, update bgn0 and update end0 bgn0=oneArr[j0][1]+1; if(j0<oneArr.length-1)end0=oneArr[j0+1][0]-1; <a name="docC219"> Key point is j0+1 First iteration (j0=0) j0+1 is level ZeRo, see 'ZeRo' below onePP= 11,15,0 // j0=0 19,29,ZeRo // j0=1 Second iteration convert blue to )→({PiorQ{notP{D},E}} Same reason as red. <a name="docC220"> Third iteration convert purple to ∧F))↔({PiorQ{G,notP{H}}} Third iteration (j0=2) j0+1 is j0=3 level OnE. see 'OnE' below onePP= 11,15,0 // j0=0 19,29,ZeRo // j0=1 36,46,0 // j0=2 1,16,OnE // j0=3 <a name="docC221"> Break condition 2. if(onePP[j0][2]>0)break; that is 2. if('OnE'>0)break; that is 2. if(1>0)break; this '1>0' is true, break from for(j0) loop. This break correspond to above purple string no more level 0 string right to purple. <a name="docC222"> The left over string end '∧I)' is recorded after for(j0) loop at next new1Line+='' +oneLine.substring(bgn0,oneLine.length) bgn0 value is defined at third purple iteration. end0=oneLine.length is coded after for(j0) loop. 2013-01-14-14-18 here <a name="docC223"> Above example has three level 0 string. What happen if whole equation is one big level 0 string? This whole equation do not have j0+1 definition !! No second level 0 follow first. Next see another example. Example 38, line 1 equation ~A∧~B∨~C→~D∨E∧F↔G∨~H∧I ---eq.38a <a name="docC224"> Input equation change history is ~A∧~B∨~C→~D∨E∧F↔G∨~H∧I ; user input (~A∧~B∨~C→~D∨E∧F↔G∨~H∧I) ; program use (notP{A}∧notP{B}∨notP{C}→notP{D}∨E∧F↔G∨notP{H}∧I) Box08 debug data is next oneLine= //next line ---eq.38c (notP{A}∧notP{B}∨notP{C}→notP{D}∨E∧F↔G∨notP{H}∧I) oneArr= 1,48,notP{A}∧notP{B}∨notP{C}→notP{D}∨E∧F↔G∨notP{H}∧I onePP= 0,48,0 lenPP=1 <a name="docC225"> This example has just one parenthesis pair inserted by program at outer most two ends. Break condition 3. if(j0<oneArr.length-1)end0=...; else break; satisfy immediately, because oneArr has just one element. oneArr.length=1 <a name="docC226"> First iteration j0=0, condition (j0<oneArr.length-1) is (0<1-1) 0 < 0 ? false ! Program break at condition 3. 2013-01-14-14-31 stop
<a name="docC227"> 2013-01-14-16-56 start new1Line+='' +oneLine.substring(bgn0,oneLine.length) oneLine=new1Line; historyArr[hA++]=oneLine; if(oneLine.indexOf('(')<0) //a112171445 { //next line convert '→,↔' to PiftQ(), PiffQ() oneLine=updateAnd(oneLine); //a201192105 historyArr[hA++]=oneLine; //a201192106 oneLine=oneLine.replace(/\{/g,'(').replace(/\}/g,')'); historyArr[hA++]=oneLine; //a201201139 break; } <a name="docC228"> If input ((~A∧~(B∨C))→((~D∨E)∧F))↔((G∨~H)∧I) ---eq.A5a At this point older symbolic equation is oneLine= ((notP{A}∧~(B∨C))→((notP{D}∨E)∧F))↔((G∨notP{H})∧I) ---eq.A5b newer symbolic/function equation is new1Line= ((notP{A}∧notP{PiorQ{B,C}})→({PiorQ{notP{D},E}}∧F))↔({PiorQ{G,notP{H}}}∧I) <a name="docC229"> Code line new1Line+='' +oneLine.substring(bgn0,oneLine.length) read oneLine end string '∧I)' and merge to new1Line. <a name="docC230"> Code line oneLine=new1Line; store new1Line to oneLine. Code line historyArr[hA++]=oneLine; update oneLine history array. <a name="docC231"> Code line if(oneLine.indexOf('(')<0) { oneLine=updateAnd(oneLine); //a201192105 historyArr[hA++]=oneLine; //a201192106 oneLine=oneLine.replace(/\{/g,'(').replace(/\}/g,')'); historyArr[hA++]=oneLine; //a201201139 break; } see whether in oneLine still has '('. If no more '(', job is done. break from while(1) infinite loop. Before break, call oneLine=updateAnd(oneLine); //a201192105 to convert highest level operator to function call. see docC191 purple Example 36 line 2 equation (A∨B)→(C↔D)∧(E∨G) cause error. see docA052 purple 2013-01-14-17-15 here
<a name="docC232"> Code line if(oneLine.indexOf('(')<0)break; When if() false, oneLine still has '('. When if() false, not break from while(1) Code flow come to next few lines. <a name="docC233"> //a112171405 group update //if oneLine has '(', ')' //otherwise not group update a112171442 m0=updateAll(oneLine) oneLine=m0[0]; oneArr=m0[1]; onePP=m0[2]; uChar=m0[3]; //a201152245 historyArr[hA++]=oneLine; } //while(1) <a name="docC234"> new1Line has more function call. oneLine has less function call. Updated oneLine is longer than old oneLine. oneArr[], onePP[] both not compatible with new oneLine. Code line m0=updateAll(oneLine) update all, include update oneArr[], update onePP[], and update oneLine itself. updateAll() return answer to m0. <a name="docC235"> Code line oneLine=m0[0]; oneArr=m0[1]; onePP=m0[2]; uChar=m0[3]; //a201152245 store new data to right partner. 2013-01-14-17-25 here
<a name="docC236"> ... But did not update uChar[][] ... deleted, because now m0=updateAll(oneLine) send back uChar[][] When proofread, correct/improve code at same time. //a201201503
<a name="docC237"> Above code section last line is end of while(1). Code below is outside of while(1) if(typeof(boxc06)=='object') boxc06.value+='' +'sym2fun1() record input equation change history be next.\n' +arr2str(historyArr)+'\n' return oneLine; } //function sym2fun1(arg1) <a name="docC238"> after exit from while(1) Code line oneLine=(updateAnd(oneLine)); oneLine=oneLine.replace(/\{/g,'(').replace(/\}/g,')'); first step ... document deleted, a201201505 move same code to end of (within) while(1) <a name="docC239"> Second step oneLine=oneLine.replace(/\{/g,'(').replace(/\}/g,')'); document deleted, a201201507 move same code to end of (within) while(1) <a name="docC240"> Here is the end of function sym2fun1(arg1) but it is not complete. Because function updateAll(oneLine) function updateStr(arg1,arg2,arg3) function updateArr(arg1) function updateAnd(arg1) all be part of function sym2fun1(arg1) function update***() split out let function sym2fun1(arg1) be easier. Following document will discuss function update***() 2013-01-14-18-01 stop //a201141801 stop 2013-01-20-15-11 proofread here.
<a name="docC241"> 2013-01-15-10-38 start Grey code discarded, active updateStr(). Next grey code cause infinite loop function updateStr(arg1,arg2,arg3) { //a112111734 var i0,j0,k0; if(typeof(arg1)!='string') return 'updateStr() error 01\n' if(typeof(arg2)!='string') return 'updateStr() error 02\n' if(typeof(arg3)!='string') return 'updateStr() error 03\n' k0=arg3; while(k0.indexOf(arg1)>=0) k0=k0.replace(arg1,arg2); return k0; //a112111738 } //function updateStr(arg1,arg2,arg3) <a name="docC242"> function updateStr() update string in arg3 change from arg1 to arg2 if arg1="~P" if arg2="notP{P}" if arg3="(~P∨Q)↔((~P)∧(~Q))" output is "(notP{P}∨Q)↔((notP{P})∧(~Q))"
<a name="docC243"> 2013-01-15-10-45 here If user input equation is "(~P∨Q)↔((~P)∧(~Q))" It is possible to call updateStr('~P','notP{P}','(~P∨Q)') Here '(~P∨Q)' is partial of input. or call updateStr('~P','notP{P}','(~P∨Q)↔((~P)∧(~Q))') Here '(~P∨Q)↔((~P)∧(~Q))' is whole of input. Because program convert negation as first step modify whole of input is called oneLine=updateStr(old0,new0,oneLine); <a name="docC244"> Above is function updateStr() Below function updateArr() modify whole of user input equation. Same example input "(~P∨Q)↔((~P)∧(~Q))" It is necessary to call as function updateArr("(~P∨Q)↔((~P)∧(~Q))") can not call as function updateArr("(~P∨Q)") Because function updateArr() read whole input equation oneLine build oneArr[]. oneLine, oneArr[] and onePP[] are whole equation variables. <a name="docC245"> function updateArr(arg1) { //a112111800 if(typeof(arg1)!='string') return 'updateArr() error 01\n' var twoLine=arg1; var twoPP=matchParenthesis(twoLine); if(typeof(twoPP)=='string')return twoPP; var lenPP=twoPP.length; var twoArr=[]; var x0; for(x0=0;x0<lenPP;x0++) { //a112060948 twoArr[x0]=[]; twoL1=twoLine.substring(twoPP[x0][0]+1,twoPP[x0][1]); twoArr[x0][0]=twoPP[x0][0]+1; twoArr[x0][1]=twoPP[x0][1]; twoArr[x0][2]=twoL1; } //for(x0=0;x0<lenPP;x0++) return twoArr; } //function updateArr(arg1) //a112111821 <a name="docC246"> If input equation is "(~P∨Q)↔((~P)∧(~Q))" Code line twoPP=matchParenthesis(twoLine); return value as following twoPP= [[0,5,0], [8,11,0], [13,16,0], [7,17,1] ] <a name="docC247"> twoPP first row [0,5,0] say left '(' at 0, right ')' at 5. This pair is level 0. No more '()' in level 0. twoPP fourth row [7,17,1] say left '(' at 7, right ')' at 17. This pair is level 1. It must have level 0 '()' in level 1. Both level 0 [8,11,0], and level 0 [13,16,0] are in level 1 [7,17,1] . <a name="docC248"> Equation ruler scale is next (~P_Q)_((~P)_(~Q)) 012345678901234567 0 1 1 Here twoPP[] is an array, represent no error condition. If input string has four '(' and five ')', twoPP is a string of error message. <a name="docC249"> Code line if(typeof(twoPP)=='string')return twoPP; detect error condition. If error, return error message and stop. function updateArr() use twoArr=[]; function sym2fun1() use oneArr=[]; twoArr and oneArr are same thing. different name in different function. <a name="docC250"> Input equation "(~P∨Q)↔((~P)∧(~Q))" has twoPP= [[0,5,0], //twoPP[0] [8,11,0], //twoPP[1] [13,16,0], //twoPP[2] [7,17,1] //twoPP[3] ] lenPP=twoPP.length=4 elements <a name="docC251"> Code line for(x0=0;x0<lenPP;x0++) let x0 step over 0,1,2,3 Consider x0=0 for (~P∨Q) Equation ruler scale is next (~PvQ)_((~P)_(~Q)) 012345678901234567 0 1 1 <a name="docC252"> Code line twoArr[x0]=[]; declare twoArr[x0]=twoArr[0] is an array. After this point program accept twoArr[0][0], twoArr[0][1] etc. Code line twoL1=twoLine.substring(twoPP[x0][0]+1,twoPP[x0][1]); extract a string ~P∨Q from (~P∨Q) and save ~P∨Q to twoL1. <a name="docC253"> twoPP[x0]=twoPP[0]=[0,5,0] twoPP[x0][0]+1=twoPP[0][0]+1=0+1=1 This 1 point to '~' in (~P∨Q) Above is string begin point twoPP[x0][0]+1 twoLine.substring(twoPP[x0][0]+1,twoPP[x0][1]) Below is string end point twoPP[x0][1] twoPP[0]=[0,5,0] twoPP[x0][1]=twoPP[0][1]=5 <a name="docC254"> This 5 point to ')' in (~P∨Q) Begin point is first byte of target string. End point is first byte AFTER target string. In (~P∨Q) from 1 to 5, we extract '~P∨Q' save to variable twoL1='~P∨Q' <a name="docC255"> Code line twoArr[x0][0]=twoPP[x0][0]+1; record 1, 1 is string '~P∨Q' first byte '~' location 1. Code line twoArr[x0][1]=twoPP[x0][1]; record 5, 5 is string '~P∨Q' OUT-OF-Range first byte ')' location 5. <a name="docC256"> twoL1 is defined at docC251, twoL1 is applied at code line twoArr[x0][2]=twoL1; record target string '~P∨Q' twoArr[x0][1], twoArr[x0][1], twoArr[x0][2] form twoArr[x0]=twoArr[0]=[1,5,'~P∨Q'] This is another function sym2fun1() oneArr first element value oneArr[0]=[1,5,'~P∨Q'] Later elements repeat same process for different x0 value. <a name="docC257"> Actually, user input equation (~P∨Q)↔((~P)∧(~Q)) output next oneLine= (notP{P}∨Q)↔((notP{P})∧(notP{Q})) oneArr= 1,10,notP{P}∨Q 14,21,notP{P} 24,31,notP{Q} 13,32,(notP{P})∧(notP{Q}) Explanation for 'notP{P}', or explanation for '~P' have same reason. function updateArr(arg1) document end here. 2013-01-15-11-53 stop
<a name="docC258"> 2013-01-15-15-21 start To change a symbolic equation to a function equation, need a symbol to function name matching table. Next variable s2f1[] is such a table. s2f1 = Symbol TO Function 1 st kind. s2f2 will be 2 nd kind for some day in future. <a name="docC259"> var s2f1= [['~', 'notP'], ['∨', 'PiorQ'], ['⊻', 'PxorQ'], //~(P↔Q) ['∧', 'PandQ'], ['→', 'PiftQ'], ['←', 'PfulQ'], ['↔', 'PiffQ'], ['⇒', 'PiftQ'], ['⇐', 'PfulQ'], ['⇔', 'PiffQ'], ['|', 'PvulQ'], //a112311954 PvulQ() nand==~(P∧Q), Sheffer Stroke ['⊽', 'PpulQ'], //a112312135 PpulQ() nor == ~(P∨Q) <a name="docC260"> //dul,nul etc. 乙人丩力匕卜厂又 ['乙', 'PdulQ'], //always true, dull ['人', 'PgulQ'], //always P, ignore Q ['丩', 'PhulQ'], //always Q, ignore P ['力', 'PtulQ'], //always~Q, ignore P ['匕', 'PsulQ'], //~(P→Q) ['卜', 'PrulQ'], //always~P, ignore Q ['厂', 'PqulQ'], //~(P←Q) ['又', 'PnulQ'] //always false, null ] //s2f1[][] ; <a name="docC261"> var ubyte=''; //a201032046 for(var ii=0;ii<s2f1.length;ii++) ubyte+=s2f1[ii][0]; //a201032047 <a name="docC262"> Frequently used operator are ['~', 'notP'], ['∨', 'PiorQ'], ['∧', 'PandQ'], ['→', 'PiftQ'], ['↔', 'PiffQ']. Other are repeat ['⇒', 'PiftQ'], ['⇔', 'PiffQ'], <a name="docC263"> and dependent ['|', 'PvulQ'], // NAND, Sheffer Stroke ['⊽', 'PpulQ'], // NOR The rest are rare used. "乙人丩力匕卜厂又" are Chinese characters. docA100 has brief. <a name="docC264"> Code lines var ubyte=''; //a201032046 for(var ii=0;ii<s2f1.length;ii++) ubyte+=s2f1[ii][0]; //a201032047 build ubyte from s2f1[ii][0]. Change made in s2f1[] automatic update in ubyte. Both s2f1[] and ubyte are global variable. 2013-01-15-15-30 stop
2013-01-15-15-38 start <a name="docC265"> Next function updateAnd(arg1) will convert from "P∨Q" to "PiorQ{P,Q}", convert from "notP{P}∨Q" to "PiorQ{notP{P},Q}" Around 2009-02 to 2009-04 LiuHH did not wrote code for this conversion in program complex2.htm . Now in logictt2.htm symbol to function name conversion success. <a name="docC266"> function updateAnd(arg1) { //a112132106 var oneL1=arg1; var quote0="()[]<>"; //a112151338 var i2,j2,k2; for(i2=0;i2<oneL1.length;i2++) if((j2=quote0.indexOf(oneL1.charAt(i2)))>=0) { break; } //if(i2>=oneL1.length) //a112132118 if(i2<oneL1.length) //a112151339 return 'updateAnd() error 01\n' <a name="docC267"> Code line var oneL1=arg1; is redundant. Code can be function updateAnd(oneL1) and drop var oneL1=arg1; This redundant code do not hurt program. <a name="docC268"> logictt2.htm allow user use "()" or "{}" or "[]" or "<>" as logic equation boundary bytes. First thing program do is to convert all "{}" or "[]" or "<>" to "()". During process, "()" represent not done part and "{}" represent done part. That is during process, "()" change to "{}" one by one. function updateAnd(arg1) convert from "notP{P}∨Q" to "PiorQ{notP{P},Q}". If function updateAnd(arg1) see "()" or "[]" or "<>", return error message. <a name="docC269"> Code line var quote0="()[]<>"; //a112151338 define reject list. for(i2) and if(j2) and if(i2) exam input string, reject when necessary.
<a name="docC270"> 2013-01-15-16-04 here Not reject, continue process. Next code important point is search for operator ['∨', 'PiorQ'], ['∧', 'PandQ'], ['→', 'PiftQ'], ['↔', 'PiffQ']. etc. replace with function name string. <a name="docC271"> var ans2=''; //a112132209 var uChar=[]; //a112132015 var uC=0; var andCnt=0; //a112151545 var iffCnt=0; ans2 record converted string. uChar[] record operator (Unicode) bytes. Assume target string is "notP{P}∨Q" location uChar[*][0] // 7 , 7th is '∨' operator uChar[*][1] //'∨' , operator is '∨' priority uChar[*][2] // 1 , '∨' priority 1 <a name="docC272"> andCnt sum the total of "∨,⊻,∧,|,⊽ ". iffCnt sum the total of "→⇒↔⇔=←⇐". andCnt and iffCnt one must be zero. function updateAnd() process priority 1 only string or priority 2 only string, not both.
<a name="docC273"> 2013-01-15-16-28 here for(j2=0;j2<oneL1.length;j2++) { if(ubyte.indexOf(oneL1.charAt(j2))>=0) { if(oneL1.charAt(j2)=='~') return 'updateAnd() error 02.\n' uChar[uC]=[]; uChar[uC][0]=j2; uChar[uC][1]=oneL1.charAt(j2); //<a name="docC274"> if(oneL1.charAt(j2)=='∨' //"or" ||oneL1.charAt(j2)=='∧' //"and" ||oneL1.charAt(j2)=='⊻' //"xor" ||oneL1.charAt(j2)=='|' //"nand" //a201051336 ||oneL1.charAt(j2)=='⊽' //"nor" //add '|','⊽' ) { //"not" highest priority, //"or", "and", "xor", "nand", "nor" second. //"if then" and "if and only if" and //"reverse if then" third. uChar[uC][2]=1; //run ∨,⊻,∧,|,⊽ first andCnt++; //a112151546 } //<a name="docC275"> else { uChar[uC][2]=2; //run →,←,↔ second iffCnt++; //a112151547 } uC++; } //if(ubyte.indexOf(oneL1.charAt(j2))>=0) } //for(j2=0;j2<oneL1.length;j2++) //input string do not have "∨,⊻,∧" //and do not have "→,←,↔" if(andCnt==0&&iffCnt==0) return oneL1; //a112151548 <a name="docC276"> From s2f1[] build ubyte, ubyte has next value. ubyte= "~∨⊻∧→←↔⇒⇐⇔|⊽乙人丩力匕卜厂又" Assume user input ~A∧~B∨~C→~D∨E∧F↔G∨~H∧I ---eq.38a then (~A∧~B∨~C→~D∨E∧F↔G∨~H∧I) ; program use function updateAnd(arg1) receive arg1=oneL1= "notP{A}∧notP{B}∨notP{C}→notP{D}∨E∧F↔G∨notP{H}∧I" <a name="docC277"> Code line for(j2=0;j2<oneL1.length;j2++) let j2 step over oneL1= "notP{A}notP{B}∨notP{C}→notP{D}∨E∧F↔G∨notP{H}∧I" 01234567 <a name="docC278"> Code line if(ubyte.indexOf(oneL1.charAt(j2))>=0) { exam each byte in oneL1 with ubyte= "~∨⊻→←↔⇒⇐⇔|⊽乙人丩力匕卜厂又" When j2=0, oneL1.charAt(j2)='n', in ubyte not find 'n', then ubyte.indexOf(oneL1.charAt(j2)) has value -1. //j2=7 ruler 'notP{A}' all not enter if(ubyte) body. Next byte j2=7, oneL1.charAt(7)=''. In ubyte 3rd location find '' code if(ubyte.indexOf(oneL1.charAt(j2))>=0) become if(("~∨⊻→←↔⇒⇐⇔|⊽乙人丩力匕卜厂又").indexOf('')>=0) become if(3>=0), evaluate to true, enter if(ubyte) body. <a name="docC279"> Code line if(oneL1.charAt(j2)=='~') return 'updateAnd() error 02.\n' reject '~' in oneL1. Because function updateAnd(arg1) not process '~'. If not reject, build matching table uChar[uC][] <a name="docC280"> Code line //uChar is used to build partsArr uChar[uC]=[]; declare uChar[uC] is an array. Code line uChar[uC][0]=j2; assign '∧' location j2 to uChar[uC][0]. Code line uChar[uC][1]=oneL1.charAt(j2); assign byte '∧' to uChar[uC][1]. <a name="docC281"> Code line if(oneL1.charAt(j2)=='∨' //"or" ||oneL1.charAt(j2)=='∧' //"and" ||oneL1.charAt(j2)=='⊻' //"xor" ||oneL1.charAt(j2)=='|' //"nand" //a201051336 ||oneL1.charAt(j2)=='⊽' //"nor" //add '|','⊽' ) determine operator has priority 1 or priority 2. If it is either one of "∨,⊻,∧,|,⊽" in code line uChar[uC][2]=1; assign priority 1 to uChar[uC][2] in code line andCnt++; increase AND counter by one. <a name="docC282"> If user input equation is ~A∧~B∨~C→~D∨E∧F↔G∨~H∧I ---eq.38a Program cut equation at Priority 2 bytes '→' and '↔'. Priority 1 section are '~A∧~B∨~C', '~D∨E∧F', 'G∨~H∧I' <a name="docC283"> Part of equation "~A∧~B∨~C" converted to "notP{A}∧notP{B}∨notP{C}" Program call updateAnd("notP{A}∧notP{B}∨notP{C}") updateAnd() build two variable array uChar= [[7,'∧',1], [15,'∨',1]] Why say it is two variable array? see next uChar[var1][var2] uChar[0]=[7,'∧',1] uChar[1]=[15,'∨',1] uChar[0][1]='∧' uChar[1][0]=15 <a name="docC284"> If operator is not in "∨,⊻,∧,|,⊽", then they all belong to priority 2 which include frequently used operator "→⇒↔⇔" dependent '|' NAND, Sheffer Stroke dependent '⊽' NOR //moved to priority 1 and rare used "乙人丩力匕卜厂又←" <a name="docC285"> Why "dependent"? because nand(P,Q)==~(P∧Q), and nor(P,Q) ==~(P∨Q). P|Q and ~(P∧Q) both be F,T,T,T P⊽Q and ~(P∨Q) both be F,F,F,T <a name="docC286"> rare used operator lump with "→,↔,|,⊽" There is uncertainty in it. LiuHH did not set "乙人丩力匕卜厂又" to priority 3. Because "乙人丩力匕卜厂又" are rare used. If reader use them, add '()' make your intention clear. 2013-01-15-17-26 stop
<a name="docC287"> if(andCnt>0&&iffCnt>0) return 'updateAnd() error 03\n' var partsArr=[]; //a112132131 var pA=0; var bgn0=0; var end0=uChar[0][0]; for(j2=0;j2<uChar.length;j2++) { end0=uChar[j2][0]; partsArr[pA++]=oneL1.substring(bgn0,end0); k2=ubyte.indexOf(uChar[j2][1]); partsArr[pA++]=s2f1[k2][1]; //a112132214 bgn0=uChar[j2][0]+1 } //for(j2=0;j2<uChar.length;j2++) partsArr[pA++]=oneL1.substring(end0+1,oneL1.length); <a name="docC288"> 2013-01-15-18-01 start Assume user input ~A∧~B∨~C→~D∨E∧F↔G∨~H∧I ---eq.38a function sym2fun1(arg1) receive eq.38a . change "~A∧~B∨~C" to "notP{A}∧notP{B}∨notP{C}" then call updateAnd("notP{A}∧notP{B}∨notP{C}") <a name="docC289"> From this section equation, updateAnd() build one variable array partsArr= //partsArr is used here ['notP{A}', 'PandQ', 'notP{B}', 'PiorQ', 'notP{C}'] <a name="docC290"> At earlier time, updateAnd() build two variable array uChar= [[7,'∧',1], [15,'∨',1]] Now uChar is used to build partsArr. <a name="docC291"> Code line var partsArr=[]; //a112132131 var pA=0; declare partsArr be an array, integer pA be partsArr parameter. <a name="docC292"> Code line var bgn0=0; var end0=uChar[0][0]; assign value to bgn0 and end0. If input string is "notP{A}∧notP{B}∨notP{C}" then get uChar[0]=[7,'∧',1] uChar[0][0]=7 <a name="docC293"> "notP{A}∧notP{B}∨notP{C}" has next ruler picture notP{A}^notP{B}_notP{C} 01234567890123456789012 0 1 2 end0=uChar[0][0]=7 location 7 is operator '∧'=uChar[0][1] '∧' has priority 1=uChar[0][2] <a name="docC294"> Code line for(j2=0;j2<uChar.length;j2++) { let j2 step over uChar= [[7,'∧',1], [15,'∨',1]] that is j2=0 and j2=1 two iterations. <a name="docC295"> Code line end0=uChar[j2][0]; assign end0 value from uChar[j2][0] When j2=0, end0=uChar[j2][0]=7 location of '∧', end of 'notP{A}' When j2=1, end0=uChar[j2][0]=15 location of '∨', end of 'notP{B}' <a name="docC296"> Code line partsArr[pA++]=oneL1.substring(bgn0,end0); record 'notP{A}' to partsArr[0] at j2=0 record 'notP{B}' to partsArr[2] at j2=1 partsArr[0] jump to [2]? how about [1]? In between partsArr[1] process at next code line. <a name="docC297"> Code line k2=ubyte.indexOf(uChar[j2][1]); if j2=0, in ubyte search for '∧'. if j2=1, in ubyte search for '∨'. ubyte has the value ubyte= "~→←↔⇒⇐⇔|⊽乙人丩力匕卜厂又" if j2=0, for '∧', k2 receive 3 if j2=1, for '∨', k2 receive 1 '~' be 0, '∨' be 1, '⊻' be 2 etc. <a name="docC298"> Next code line is important partsArr[pA++]=s2f1[k2][1]; above code line convert from '∨' to 'PiorQ'. k2 receive value from ubyte, k2=ubyte.indexOf(uChar[j2][1]); k2 apply its value to s2f1?! partsArr[pA++]=s2f1[k2][1]; YellowMarket give me 20% discount coupon, I goto Goldmart to use YellowMarket discount coupon?! <a name="docC299"> NO! it is not this case, it is GoldenCity give me 20% discount coupon, I goto Goldmart to use GoldenCity discount coupon. Because Goldmart and GoldenCity are one owner. Because ubyte is derived from s2f1[][] . Please review early document. <a name="docC300"> If j2=0, for '∧', k2 receive 3 s2f1[k2][1] become s2f1[3][1] s2f1[3][0] is '∧' s2f1[3][1] is 'PandQ' re-display first five lines for reference. s2f1= [['~', 'notP'], ['∨', 'PiorQ'], //s2f1[1] ['⊻', 'PxorQ'], //~(P↔Q) ['∧', 'PandQ'], //s2f1[3] ['→', 'PiftQ'], <a name="docC301"> If j2=1, for '∨', k2 receive 1 s2f1[k2][1] become s2f1[1][1] s2f1[1][0] is '∨' s2f1[1][1] is 'PiorQ' Input "notP{A}∧notP{B}∨notP{C}" break to ['notP{A}', '∧', 'notP{B}', '∨', 'notP{C}'] <a name="docC302"> Code line partsArr[pA++]=s2f1[k2][1]; change above array to next array partsArr= ['notP{A}', 'PandQ', 'notP{B}', 'PiorQ', 'notP{C}'] <a name="docC303"> partsArr[] allow code change from "notP{A}∧notP{B}∨notP{C}" to "PiorQ{PandQ{notP{A},notP{B}},notP{C}}" partsArr work in action few pace below. <a name="docC304"> Code line bgn0=uChar[j2][0]+1 } //for(j2=0;j2<uChar.length;j2++) update next iteration bgn0 value. Assume input "notP{A}∧notP{B}∨notP{C}" Assume now j2=0. uChar= [[7,'∧',1], [15,'∨',1]] uChar[j2][0]=uChar[0][0]=7 bgn0=uChar[j2][0]+1=7+1=8 in "notP{A}^notP{B}∨notP{C}" 012345678 8 do point to next iteration 'notP{B}' first byte 'n'. <a name="docC305"> Input string "notP{A}∧notP{B}∨notP{C}" for(j2) loop first iteration process red notP{A}∧ for(j2) loop second iteration process blue notP{B}∨, after blue no operator, exit from for(j2) loop. Next code line partsArr[pA++]=oneL1.substring(end0+1,oneL1.length); record purple 'notP{C}' so that result string is complete. <a name="docC306"> Twist [0],[1],[2],[3],[4] to [3],[1],[0],[2],[4] For input "notP{A}∧notP{B}∨notP{C}" at this point, we get partsArr= ['notP{A}', //partsArr[0] 'PandQ', //partsArr[1] 'notP{B}', //partsArr[2] 'PiorQ', //partsArr[3] 'notP{C}'] //partsArr[4] partsArr has 5 elements, partsArr.length=5 Next for(j2) loop use partsArr.length 2013-01-15-19-42 here
<a name="docC307"> For above input and partsArr we want "PiorQ{PandQ{notP{A},notP{B}},notP{C}}" //[3] [1] [0] [2] [4] Here [0] to [4] are partsArr[] elements Why twist [0],[1],[2],[3],[4] to strange [3],[1],[0],[2],[4]? <a name="docC308"> Two factor determine this twist. 1. change A∧B to ∧(A,B) to PandQ(A,B) 2. change A∧B∨C to (A∧B)∨C , that is not change to A∧(B∨C) Following is twist code. <a name="docC309"> ans2=partsArr[0]; for(j2=1;j2<partsArr.length;j2+=2) { //a112132210 ans2=partsArr[j2]+'{'+ans2 +','+partsArr[j2+1]+'}'; } //for(j2=0;j2<partsArr.length;j2+=2) return ans2; } //function updateAnd(arg1) a112132221 <a name="docC310"> Code line ans2=partsArr[0]; record partsArr[0] to ans2. Later code add more to ans2 left and ans2 right. <a name="docC311"> Code line for(j2=1;j2<partsArr.length;j2+=2) run a for(j2) loop, start from j2=1 and each iteration increase j2 by 2. This is an un-usual for() loop. <a name="docC312"> Code line ans2=partsArr[j2]+'{'+ans2 +','+partsArr[j2+1]+'}'; sum terms to answer string. First iteration, j2=1. ans2= partsArr[j2] //'PandQ' +'{' //'{' +ans2 //'notP{A}' +',' //',' +partsArr[j2+1] //'notP{B}' +'}' //'}' ; <a name="docC313"> First iteration string to 'PandQ{notP{A},notP{B}}' This is new ans2='PandQ{notP{A},notP{B}}' <a name="docC314"> Next iteration j2=j2+2=1+2=3 next stop criteria j2<partsArr.length=5 3<partsArr.length=5 true, continue second iteration, j2=3. ans2= partsArr[j2] //'PiorQ' +'{' //'{' +ans2 //'PandQ{notP{A},notP{B}}' +',' //',' +partsArr[j2+1] //'notP{C}' +'}' //'}' ; second iteration string sum to 'PiorQ { PandQ{notP{A},notP{B}} , notP{C} }' <a name="docC315"> Next iteration j2=j2+2=3+2=5 next stop criteria j2<partsArr.length=5 5<partsArr.length=5 false. break from for(j2=0;j2<partsArr.length;j2+=2) Job is DONE !! <a name="docC316"> Code line return ans2; send answer 'PiorQ{PandQ{notP{A},notP{B}},notP{C}}' back to original call function. function updateAnd(arg1) document done. 2013-01-15-20-12 stop
<a name="docC317"> 2013-01-15-22-25 start function updateAll(oneLine) has no thing new. When oneLine change length from, for example "notP{A}∧notP{B}∨notP{C}" to "PiorQ{PandQ{notP{A},notP{B}},notP{C}}" <a name="docC318"> Its parenthesis pair matching record onePP is not valid. Because short line parenthesis pair index and long line parenthesis pair index are different. If apply short line onePP to long line get mess up result. When user input equation change, onePP and oneArr must update. <a name="docC319"> function updateAll(oneLine) read new longer equation and modify onePP and oneArr, send back to a variable m0 then distribute new data from m0[0], m0[1], m0[2], m0[3] to oneLine, oneArr, onePP and uChar. Next is a sample code. m0=updateAll(oneLine) oneLine=m0[0]; oneArr=m0[1]; onePP=m0[2]; uChar=m0[3]; <a name="docC320"> function updateAll(oneLine) //a112171319 { if(oneLine.indexOf('(')<0) return oneLine; //a112171454 if(typeof(oneLine)!='string') return 'updateAll() error 01' var oneArr=updateArr(oneLine); if(typeof(oneArr)=='string')return oneArr; var onePP=matchParenthesis(oneLine); if(typeof(onePP)=='string')return onePP; <a name="docC321"> During above function updateAll() document writing, made change at a201152244 delete and add line uChar=m0[3]; //a201152245 2013-01-15-23-08 stop <a name="docC322"> 2013-01-16-07-52 start Code line if(oneLine.indexOf('(')<0) return oneLine; check input string has '(' or not. If not find, this string is done, no need process. Return to calling function. <a name="docC323"> redundant document, deleted a201201755 <a name="docC324"> Code line if(typeof(oneLine)!='string') return 'updateAll() error 01' make sure input is a string. Can not be an integer, can not be an array. <a name="docC325"> Code line var oneArr=updateArr(oneLine); onePP=matchParenthesis(oneLine); record updated oneArr[] and onePP[] data.
<a name="docC326"> var i0,j0,k0,j3,again0=0; var j5; //a201141434 var oneL1,uChar,uC; //a201141435 change from for(j0) to for(j5) for(j5=0;j5<oneArr.length;j5++) { <a name="docC327"> Code line for(j5=0;j5<oneArr.length;j5++) {...} build uChar[]. If input equation has redundant '()' uChar[] may record nothing, uChar.length be zero, this case, program change again0 from 0 to 1. It is a flag indicate input has extra '()'. 2013-01-16-08-15 stop <a name="docC328"> 2013-01-16-18-58 start logictt2.htm allow reader use redundant parenthesis pair. logicmr2.htm NOT allow reader use redundant parenthesis pair. The following example equations cause logictt2.htm change again0 from 0 to 1 LiuHH check these equations compare answer with logicmr2.htm. All get same true/false answer. If you like to know the input equation difference between logictt2.htm and logicmr2.htm, here is the general pattern <a name="docC329"> working date/time //logictt2.htm example number, line number logictt2 example equationA with redundancy logictt2 example equationB logicmr2 accept logictt2 example equation T/F answer logicmr2 same equation T/⊥ answer logicmr2 same equationC = equationB confirm date/time If you paste equationB to logicmr2, logicmr2.htm auto convert to equationC. <a name="docC330"> Purple color equation, logictt2.htm style, logicmr2.htm reject Red color equation, both logictt2.htm and logicmr2.htm accept Blue color equation, logicmr2.htm style equation. logicmr2.htm is a mirror page of logicmr2.htm and truthtable.html have same code. BUT Red color equation will run in logicmr2.htm and will not run in truthtable.html , because LiuHH add conversion function to logicmr2.htm . truthtable.html no such conversion. <a name="docC331"> 2013-01-14-19-26 // a201141910 example 35 line 1 (P∨(Q∨R))↔((P∨Q)∨R)↔(((R∨Q)∨P)) (((P∨(Q∨R))↔((P∨Q)∨R))↔((R∨Q)∨P)) T,T,T,T,T,T,T,F T,T,T,T,T,T,T,⊥ (((Pv(QvR))=((PvQ)vR))=((RvQ)vP)) 2013-01-14-19-28 match <a name="docC332"> 2013-01-14-19-29 //example 34 (¬(P↔Q))↔((P∧(¬Q))∨(Q∧(¬P))) (~(P↔Q))↔((P∧(~Q))∨(Q∧(~P))) (~(P↔Q)↔((P∧~Q)∨(Q∧~P))) T,T,T,T T,T,T,T (~(P=Q)=((P&~Q)v(Q&~P))) 2013-01-14-19-33 OK <a name="docC333"> 2013-01-14-19-34 //example 30 //next two lines are logictt2.htm equation P→(~(Q∨R)) //logicmr2.htm reject this equation (P→~(Q∨R)) //logicmr2.htm accept this equation F,F,F,T,T,T,T,T ⊥,⊥,⊥,T,T,T,T,T (P>~(QvR)) //logicmr2.htm use this form 2013-01-14-19-35 OK <a name="docC334"> 2013-01-14-19-36 //example 14 (P→Q)↔(~(P∧(~Q))) ((P→Q)↔~(P∧~Q)) T,T,T,T T,T,T,T ((P>Q)=~(P&~Q)) 2013-01-14-19-37 OK <a name="docC335"> 2013-01-14-19-38 //example 4 (~(P↔Q))↔((P∧(~Q))∨(Q∧(~P))) (~(P↔Q)↔((P∧~Q)∨(Q∧~P))) T,T,T,T T,T,T,T (~(P=Q)=((P&~Q)v(Q&~P))) 2013-01-14-19-39 OK <a name="docC336"> 2013-01-14-19-40 //example 3 (~(P→Q))↔(P∧(~Q)) (~(P→Q)↔(P∧~Q)) T,T,T,T T,T,T,T (~(P>Q)=(P&~Q)) 2013-01-14-19-40 ok <a name="docC337"> 2013-01-14-19-41 //example 2 (~(P∧Q))↔((~P)∨(~Q)) (~(P∧Q)↔(~P∨~Q)) T,T,T,T T,T,T,T (~(P&Q)=(~Pv~Q)) 2013-01-14-19-42 OK <a name="docC338"> 2013-01-14-19-43 //example 1 (~(P∨Q))↔((~P)∧(~Q)) ---eq.01a (~(P∨Q)↔(~P∧~Q)) T,T,T,T T,T,T,T (~(PvQ)=(~P&~Q)) 2013-01-14-19-43 OK 2013-01-16-19-25 here
<a name="docC339"> oneL1=oneArr[j5][2] uChar=[]; uC=0; for(j3=0;j3<oneL1.length;j3++) { if(ubyte.indexOf(oneL1.charAt(j3))>=0) { uChar[uC]=[]; uChar[uC][0]=j3; uChar[uC][1]=oneL1.charAt(j3); uC++; } } //for(j3=0;j3<oneL1.length;j3++) <a name="docC340"> Code line for(j3=0;j3<oneL1.length;j3++) {...} build uChar[] array. See earlier document.
<a name="docC341"> if(uC==0) //oneArr[j5] do not have { // "~∨⊻∧→←↔⇒⇐⇔" remove '(', ')' again0=1; //was update one more time, now //again0=1 is redundant () flag oneLine=oneLine.substring(0,oneArr[j5][0]-1) +'{'+oneArr[j5][2]+'}' +oneLine.substring(oneArr[j5][1]+1,oneLine.length) } //if(uC==0&&j5<oneArr.length) } //for(j5=0;j5<oneArr.length;j5++) <a name="docC342"> '-1' in 'oneArr[j5][0]-1' drop '(', replace with '{' '+1' in 'oneArr[j5][1]+1' drop ')', replace with '}' This replacement, change example 35 line 1 equation (P∨(Q∨R))↔((P∨Q)∨R)↔(((R∨Q)∨P)) from/to next three lines. '|' is change point. {PiorQ{P,{PiorQ{Q,R}}}}_{PiorQ{{PiorQ{P,Q}},R}}_({PiorQ{{PiorQ{R,Q}},P}}) ================================================|=======================| {PiorQ{P,{PiorQ{Q,R}}}}_{PiorQ{{PiorQ{P,Q}},R}}_{{PiorQ{{PiorQ{R,Q}},P}}} // '_' replace '↔' <a name="docC343"> function updateAll(oneLine) made above change, because in string ({PiorQ{{PiorQ{R,Q}},P}}) there is no operator "~∨⊻∧→←↔⇒⇐⇔", then '(' and ')' are not proper. All symbol to function name converted equation section change from '()' to '{}'.
<a name="docC344"> //after a201141957 test, delete next line //if(again0==1)updateAll(oneLine) return [oneLine,oneArr,onePP,uChar]; //a201152242 uChar } //function updateAll(oneLine) a112171332 <a name="docC345"> Here is the end of function updateAll(oneLine) function return an array [oneLine,oneArr,onePP,uChar] in which oneLine, is a string of updated input equation oneArr, onePP, uChar are three array match new oneLine. 2013-01-16-20-12 stop <a name="docC346"> 2013-01-21-09-57 start Liu,Hsinhan's code is non-professional. Early code function updateStr discarded. Following is newer version. function updateStr(arg1,arg2,arg3) { //a112111734 var i0,j0,k0; if(typeof(arg1)!='string')return 'updateStr() error 01\n' if(typeof(arg2)!='string')return 'updateStr() error 02\n' if(typeof(arg3)!='string')return 'updateStr() error 03\n' if(arg1.length==0)return 'updateStr() error 04\n';//a201210441 if(arg3.length==0)return 'updateStr() error 05\n';//a201210442 if(arg1==arg2)return arg3; //a201210443 var ostr=''; //a201210435 var bgn0=0; var end0=0; //a201210445 while((end0=arg3.indexOf(arg1,bgn0))>=bgn0) { //a201210446 ostr+=arg3.substring(bgn0,end0)+arg2 bgn0=end0+arg1.length; } ostr+=arg3.substring(bgn0,arg3.length) return ostr; //a201210520 confirmed ok } //function updateStr(arg1,arg2,arg3) <a name="docC347"> Early version function updateStr is next k0=arg3; while(k0.indexOf(arg1)>=0) k0=k0.replace(arg1,arg2); return k0; //a112111738, a201210333 del If target string is k0="abc1 abc2 abc3" If old string is arg1="abc" If new string is arg2="abcYZ" <a name="docC348"> Code while(k0.indexOf(arg1)>=0) say in k0 search for arg1. It is same as in "abc1 abc2 abc3" search for "abc". Code k0=k0.replace(arg1,arg2); say in k0 replace arg1 with arg2, same as in "abc1 abc2 abc3" replace "abc" with "abcYZ" store the new string back to k0. After 1st replacement, get "abcYZ1 abc2 abc3" After 2nd replacement, get "abcYZYZ1 abc2 abc3" etc. This is an infinite loop !! <a name="docC349"> Above ill code has no trouble in logictt2.htm. Because in logictt2.htm replace '~A' with 'notP{A}'. New string 'notP{A}' do not have old string '~A'. But if someone take this ill function updateStr() to other code and replace oldStr with newStr = oldStr+'etc', other code get infinite loop. Newer version do not have such problem. a201211021 here <a name="docC350"> Please goto Box08, click right end Box07 fill oldStr,newStr,targetStr 3 lines abc abcYZ abc1 abc2 abc3 Next click right end , answer send to Box08. There is no infinite loop. New code document is next <a name="docC351"> var ostr=''; //a201210435 var bgn0=0; var end0=0; //a201210445 Above three line initialize three variables. ostr is answer string bgn0 and end0 define selected section begin and end location. <a name="docC352"> while((end0=arg3.indexOf(arg1,bgn0))>=bgn0) { //a201210446 This while loop is while(end0>=bgn0) and define end0 as (end0=arg3.indexOf(arg1,bgn0)) It says in arg3 start from bgn0 search for arg1 and store the result to end0. Assume old string =arg1='abc' new string =arg2='abcYZ' target str =arg3='abc1 abc2 abc3' <a name="docC353"> For first iteration, bgn0=0, It says in 'abc1 abc2 abc3' start from bgn0=0 search for 'abc' and store the result to end0. target 'abc1 abc2 abc3' has 'abc' at end0=0. See next ruler abc1 abc2 abc3 01234567890123 0 1 Red abc is first match. Red 0 is first end0 value. <a name="docC354"> while(end0>=bgn0) become while(0>=0) true, enter while() {body} Code line ostr+=arg3.substring(bgn0,end0)+arg2 build answer string ostr. First iteration ostr+=arg3.substring(bgn0,end0)+arg2 above += and below = are identical ostr=ostr+arg3.substring(bgn0,end0)+arg2 become ostr=''+arg3.substring(0,0)+'abcYZ' Red '' is ostr initial value. arg3.substring(0,0) from 0 to 0? empty! result ostr='abcYZ'. <a name="docC355"> New version do not have ill side effect, main reason is output to ostr, different from input arg3. Old version has ill result, main reason is output to k0, same as input k0. <a name="docC356"> Code line bgn0=end0+arg1.length; update bgn0 to 0+'abc'.length to 0+3=3. After first iteration bgn0=3. Next is second iteration while((end0=arg3.indexOf(arg1,bgn0))>=bgn0) is (end0=arg3.indexOf(arg1,bgn0)) and while(end0>=bgn0). Next is ruler abc1 abc2 abc3 01234567890123 0 1 Red abc is second match. Red 5 is second end0 value. <a name="docC357"> while(end0>=bgn0) become while(5>=3) true, Enter while(){body} Code line ostr+=arg3.substring(bgn0,end0)+arg2 build second iteration answer. It become ostr='abcYZ'+arg3.substring(3,5)+'abcYZ' Red 'abcYZ' is first iteration ostr value. arg3.substring(3,5) record byte 3,4="1 ". Blue 'abcYZ' is arg2. Second iteration ostr value='abcYZ1 abcYZ' Similarly third iteration get ostr='abcYZ1 abcYZ2 abcYZ' <a name="docC358"> Fourth iteration bgn0=13 point to '3' in 'abc1 abc2 abc3' while((end0=arg3.indexOf(arg1,bgn0))>=bgn0) is (end0=arg3.indexOf(arg1,13)) it says in arg3='abc1 abc2 abc3' start at 13 th byte, search for 'abc'=arg1. But in 'abc1 abc2 abc3' red 3 do not have 'abc'. end0 receive value -1 for no match. <a name="docC359"> while(end0>=bgn0) become while(-1>=13) false. Stop while() loop. Come to next code line //('abc1 abc2 abc3').length=14 ostr+=arg3.substring(bgn0,arg3.length) it has next value ostr=ostr+arg3.substring(13,14) or ostr='abcYZ1 abcYZ2 abcYZ'+'3' get ostr='abcYZ1 abcYZ2 abcYZ3' final answer. code line return ostr; send answer back. function updateStr() document is done. 2013-01-21-11-57 stop <a name="docC360"> 2013-01-21-18-00 start This file logictt2.htm read user input symbolic logic equation and output to a logic truth table. If user input ~(P∨Q) program convert to notP(PiorQ(P,Q)) and use eval() to find true/false answer. <a name="docC361"> function sym2fun1(arg1) change from '~(P∨Q)' to 'notP(PiorQ(P,Q))' function logic1Line(arg1) receive 'notP(PiorQ(P,Q))' and build table
PQ answer
TT false
TF false
FT false
FF true
Table width:

<a name="docC362"> The following is document for function logic1Line(arg1) function logic1Line(arg1) //a112041436 { if(typeof(arg1)!='string') return 'logic1Line(arg1) error 01\n' arg1 in function logic1Line(arg1) is a logic equation in function call form. This equation must be a string, can not be array of strings, can not be integer. if typeof(arg1) is not 'string', return error 01.
<a name="docC363"> var i0,j0,k0; var ans0=''; var arr0; if(arg1.indexOf('\r\n')>=0) arr0=arg1.split('\r\n'); else //a112041439 arr0=arg1.split('\n'); var oneLin0=arr0[0]; if(oneLin0.length==0) return 'logic1Line(arg1) error 02\n' <a name="docC364"> Code line arr0=arg1.split('\r\n'); is not active. logictt2.htm call function sym2fun1(arg1) function logic1Line(arg1) one line at a time. This one line call is made at function runEqn(arg1) If logic1Line(arg1) receive arg1 be empty string "". Return error 02.
<a name="docC365"> var oneLine=oneLin0.replace(/\[/g,'(').replace(/\]/g,')').replace(/\{/g,'(').replace(/\}/g,')').replace(/\</g,'(').replace(/\>/g,')').replace(/ /g,'').replace(/\t/g,''); oneLine=oneLine.replace(/¬/g,'~'); //a112181630 for(i0=0;i0<oneLine.length;i0++) { if(ubyte.indexOf(oneLine.charAt(i0))>=0) return 'logic1Line(arg1) error 04\n' } <a name="docC366"> logictt2.htm allow user apply '{}', '[]', '<>' and '()' as equation group boundary. Program do parenthesis pair matching analysis require all group boundary be '()'. Above code replace '{}', '[]', '<>' with '()' Also replace '¬' with '~'. Both be negation operator. logictt2.htm use '~' as standard. These replacement is done in sym2fun1(arg1) before call logic1Line(arg1). Replacement code in logic1Line(arg1) never do any job. But first version logictt2.htm ask user input function equation, and sym2fun1(arg1) is not written. First version logictt2.htm function logic1Line(arg1) can not be lazy. <a name="docC367"> Symbolic equation is '~(P∨Q)' function equation is 'notP(PiorQ(P,Q))' function equation can not have operator bytes "~ ∨ ∧ → ↔ | ⊽ ⊻" Above for(i0=0;i0<oneLine.length;i0++) loop exam input equation oneLine, let i0 step over oneLine, take each byte oneLine.charAt(i0) compare with ubyte string "~∨⊻∧→←↔⇒⇐⇔|⊽乙人丩力匕卜厂又"; if equation has one byte found in ubyte return error 04.
<a name="docC368"> The following code is identical with earlier document from [a name="docC056"] to [a name="docC075"] //for one byte uppercase P,Q,R var upper26='ABCDEFGHIJKLMNOPQRSTUVWXYZ'; //for five byte function name PandQ var upLow52='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +'abcdefghijklmnopqrstuvwxyz'; //record one byte uppercase P,Q,R usage var upArray=new Array(26); for(i0=0;i0<upArray.length;i0++) upArray[i0]=0; //a112041452 //<a name="docC369"> for(i0=0;i0<oneLine.length;i0++) { j0=upper26.indexOf(oneLine.charAt(i0)); if(j0<0)continue; if(i0>0&&upLow52.indexOf(oneLine.charAt(i0-1))>=0) continue; if(i0<oneLine.length-1&& upLow52.indexOf(oneLine.charAt(i0+1))>=0) continue; upArray[j0]++; //a112041453 } //for(i0=0;i0<oneLine.length;i0++) //<a name="docC370"> var elemStr=''; //a112041528 for(i0=0;i0<upArray.length;i0++) if(upArray[i0]>0)elemStr+=upper26.charAt(i0); var eL=elemStr.length; if(eL==0) return 'logic1Line(arg1) error 03\n' Above code is identical with earlier document from [a name="docC056"] to [a name="docC075"] 2013-01-21-18-43 here
<a name="docC371"> var tf10=0; //a201041705 if(typeof(chkbxA12)=='object' &&chkbxA12.checked)tf10=1; //a201042004 var tbCode=0; //a112042314 if(typeof(boxc03)=='object')tbCode=1; Mathematics major reader use T/F as answer. Electronic engineer use 0/1 as answer. <a name="docC372"> Assume equation has P,Q,R three variables. T/F answer start from P,Q,R=T,T,T end at P,Q,R=F,F,F. 0/1 answer start from P,Q,R=0,0,0 end at P,Q,R=1,1,1. 0,0,0 is F,F,F ; 1,1,1 is T,T,T . Two type output are reverse (upside down) to each other. program use tf01=['T/F','0/1'] program use tf10=integer 0 or 1 tf10 four bytes come from true/false/1/0 tf10=0 output T/F tf10=1 output 0/1 <a name="docC373"> On top of Box01, there is one checkbox Output to Code line var tf10=0; //tf10=0 output T/F if(typeof(chkbxA12)=='object' &&chkbxA12.checked)tf10=1; //a201042004 say, if web page has an element chkbxA12 and if this checkbox is checked then set tf10=1 , tf10=1 output 0/1 Above user decide output to T/F or 0/1 <a name="docC374"> Below program decide output html code or not. var tbCode=0; //a112042314 if(typeof(boxc03)=='object')tbCode=1; tbCode=0 say not output html table code if typeof(boxc03)=='object' that is if boc03 is defined, page has box03, then set tbCode=1, output html table code. Code line if(typeof(boxc03)=='object') is inactive! Because manager function runEqn() see typeof(boxc03)!='object' then reject. Insist 'boxc03' be defined. 2013-01-21-19-13 stop
<a name="docC375"> 2013-01-21-21-29 start var tbStr0='';//a112042315 var tblID; var boxID; //a112042320 if(tbCode) { var randID=rand_id0(20); //a201211738 tblID='Ltbl'+randID; boxID='Lbox'+randID; //a110151457 var default500=250; //a110151509 tbStr0=oneLine+'<br>\n<table border=1 id='+tblID +' width='+default500+' ><tr>' for(i0=0;i0<elemStr.length;i0++) tbStr0+='<td>'+elemStr.charAt(i0)+'</td>' tbStr0+='<td> </td>' //space column +'<td>'+(tf10?'ans':'answer')+'</td>' tbStr0+='</tr>\n' } //if(tbCode) <a name="docC376"> logictt2.htm, logictt4.htm and logicmr2.htm all build truth table in html code, allow user copy html table and paste to user's web page. Above code write table head to output string tbStr0. Table has default width 250 no matter it is two variable P,Q or eight variables A,B,C,D,E,G,H,I. This width 250 setting may not be proper. LiuHH write a control box let user change width to different value. Here is sample table. <a name="docC377"> Three tables, three control boxes. Each box control a truth table above this box. Box-table match rely on box ID and table ID. ID must be unique. If two html elements have same ID name, both elements loss ID, both are not identifiable. To assign unique ID to several tables/boxes, code use random number generator. Default each 20 bytes. <a name="docC378"> Code if(tbCode) say if web page defined box03 then do commands in {body}. This if is not necessary in logictt2.htm, because logictt2.htm must define box03. This if() let other web page author re-use function logic1Line() and not define box03, still running and get text truth table output. <a name="docC379"> Code line var randID=rand_id0(20); request a random number string of 20 bytes long. Code line tblID='Ltbl'+randID; boxID='Lbox'+randID; build table ID tblID and box ID boxID. Both use same random number string randID but different at 'Ltbl', 'Lbox'. Code line var default500=250; set up default table width to 250. <a name="docC380"> Code line tbStr0=oneLine+'<br>\n<table border=1 id='+tblID +' width='+default500+' ><tr>' build table head. "oneLine+'<br>\n'" write equation on top of table. Following string set table border to 1 to show up table grid. Assign table ID and width. If input equation is P∨Q∧R ---eq.A7a then elemStr='PQR' and elemStr.length=3 Code line for(i0=0;i0<elemStr.length;i0++) tbStr0+='<td>'+elemStr.charAt(i0)+'</td>' add string '<td>P</td><td>Q</td><td>R</td>' to tbStr0. <a name="docC381"> Code line tbStr0+='<td> </td>' +'<td>'+(tf10?'ans':'answer')+'</td>' add '<td> space </td>' to tbStr0. add '<td>ans</td>' or '<td>answer</td>' to tbStr0. Code line tbStr0+='</tr>\n' add '</tr>\n' to end one row. (Next '<tr>' start a new row.) Up to here, get tbStr0 = 'P∨Q∧R <table border=1 id=Ltblc9fi7jkv70khfpy6m2l8 width=250 ><tr><td>P</td><td>Q</td><td>R</td><td> </td><td>answer</td></tr>' (right end of P∨Q∧R, newline use actual newline, did not use '\n' symbol) 2013-01-21-22-22 here
<a name="docC382"> what is m2[]? m2A,m2B var m0,m1,m2,m3,m4,m5,m6; m1=Math.pow(2,eL); m2=new Array(m1); for(i0=0;i0<m2.length;i0++)m2[i0]=''; If input logic equation P∨Q∧R ---eq.A7a elemStr='PQR' eL=elemStr.length=3 P has two choice T or F, Q has two choice T or F, R has two choice T or F, <a name="docC383"> P,Q,R are independent, total combination is 2*2*2=8 Code line m1=Math.pow(2,eL); get m1=8. Code line m2=new Array(m1); declare m2 be an array with 8 elements: m2[0], m2[1] ... m2[7]. Code line for(i0=0;i0<m2.length;i0++)m2[i0]=''; initialize 8 elements with empty string '' In the future, m2[0], m2[1] ... m2[7] will store string. //what is m2[]? m2A,m2B
<a name="docC384"> var tbArr=new Array(m1); for(i0=0;i0<tbArr.length;i0++) tbArr[i0]=new Array(2+eL); Above code lines need an example table. Assume logic equation is P∨Q∧R ---eq.A7a logictt2.htm box03 generate next table. <a name="docC385">
PQR answer
TTT true
TTF false
TFT true
TFF false
FTT true
FTF false
FFT false
FFF false
Table width:
<a name="docC386"> Table dimension 9*5, 9 rows, 5 columns. Columns are "P, Q, R, space, answer". Equation 'P∨Q∧R' has three variables eL=3 for "P, Q, R" three columns. 2 in '2+eL' for two more col. space, answer. Above is 5 columns, below is 9 rows. P,Q,R three variables each has T.F two choices, total 2*2*2=8 different table rows. Top "P, Q, R, space, answer" is one more row. 2^eL+1=2^3+1=8+1=9. <a name="docC387"> Code line var tbArr=new Array(m1); declare tbArr be an array with 8 elements: tbArr[0], tbArr[1] ... tbArr[7]. Code line for(i0=0;i0<tbArr.length;i0++) tbArr[i0]=new Array(2+eL); declare tbArr[i0] be an array with 5 elements: if i0=0, it is tbArr[0][0],tbArr[0][1], tbArr[0][2],tbArr[0][3],tbArr[0][4]. i0=1 to i0=7 similar defined. <a name="docC388"> Question, //what is m2[]? m2B,m2C Code line var tbArr=new Array(m1); Code line m2=new Array(m1); both be array of m1=8 size. What is the difference between tbArr and m2? There are two differences. First tbArr[][] is two variables array, m2[] is one variable array, <a name="docC389"> what is m2[]? Second, tbArr[][] is used to build truth table store T or F value. m2[] is used to build evaluation string and send to eval() to find P∨Q∧R true or false value. One example of m2[] string is m2[0]='P=true,Q=true,R=true,(PandQ(PiorQ(P,Q),R))' command eval(m2[0]) will return true . this result will fill in to tbArr[0][4] as answer to first P,Q,R combination. 2013-01-21-23-25 stop
<a name="docC390"> 2013-01-22-10-56 start Assume input equation is P∨Q∧R ---eq.A7a Its truth table list at docC385 Table left three columns, repeat here. Next eight lines. P=true ,Q=true ,R=true P=true ,Q=true ,R=false P=true ,Q=false,R=true P=true ,Q=false,R=false P=false,Q=true ,R=true P=false,Q=true ,R=false P=false,Q=false,R=true P=false,Q=false,R=false <a name="docC391"> Observe the pattern. Left column has first variable P value. Middle col. has second variable Q value. Right column has third variable R value. P column value: T,T,T,T,F,F,F,F Q column value: T,T,F,F,T,T,F,F R column value: T,F,T,F,T,F,T,F P column value period 8=2^3 Q column value period 4=2^2 R column value period 2=2^1 <a name="docC392"> Extend to broader case, if variables are A,B,C,D,E five variables. A column value period 32=2^5 B column value period 16=2^4 C column value period 8=2^3 D column value period 4=2^2 E column value period 2=2^1 Other number of variables have similar analysis. This combination pattern cover all variables value.
<a name="docC393"> Next code determine P,Q,R true/false value. var period0; var T01='=true '; var F01='=false'; //use T/F if(tf10==1) //use 0/1 {T01='=false';F01='=true ';} //a201042006 <a name="docC394"> Code line var T01='=true '; var F01='=false'; assign string '=true ' to variable T01 assign string '=false' to variable F01 If user request output T/F answer, above is right setting. Do not make change. If user request output 0/1 answer, tf10 has value 1. Code line if(tf10==1) become true. Code flow enter {T01='=false';F01='=true ';} switch T01,F01 definitions. It can NOT be {T01='=0';F01='=1';} because eval() need Boolean true/false, not integer 0/1. <a name="docC395"> If input equation is M∨N ---eq.A8a Setting T01='=true '; F01='=false' generate M=true ,N=true M=true ,N=false M=false,N=true M=false,N=false Above first line true,true. <a name="docC396"> Below first line false,false. Setting T01='=false'; F01='=true ' generate M=0,N=0 which is M=false,N=false M=0,N=1 which is M=false,N=true M=1,N=0 which is M=true ,N=false M=1,N=1 which is M=true ,N=true 2013-01-22-11-33 here
<a name="docC397"> If input equation is P∨Q∧R ---eq.A7a eL=3 and m1=8 which apply to next loops. for(i0=0;i0<eL;i0++) { //a112041541 period0=Math.pow(2,eL-i0); //a112041931 m5=m6=''; //a112042335 Code line for(i0=0;i0<eL;i0++) say let i0 scan over P,Q,R three variables. because eL=3 variables. <a name="docC398"> Code line period0=Math.pow(2,eL-i0); say for i0 th variable, period is pow(2,eL-i0) First variable P has i0=0. First variable P has period 8=2^3=pow(2,3-0) Second variable Q has i0=1. Second variable Q has period 4=2^2=pow(2,3-1) Third variable R has i0=2. Third variable R has period 2=2^1=pow(2,3-2) <a name="docC399"> Code line m5=m6=''; initialize m5,m6 to empty string. m5,m6 will be string, not integer, not Boolean. What is the difference between m5 and m6? eval('P=true ,Q=true ,PiffQ(...)') correct eval('P=t ,Q=t ,PiffQ(...)') wrong eval('P=0 ,Q=0 ,PiffQ(...)') wrong m5 store '=true' or '=false' send to eval() see future code m2[j0]+=elemStr.charAt(i0)+m5+',' and tf=eval(m2[i0]+oneLine)+''; <a name="docC400"> On the other hand, HTML Truth table
MN answer
TT true
TF true
FT true
FF false
Table width:
If use m5 string '=true ' ,'=false' wrong. Future code line m6=m5.replace('=true ','1').replace('=false','0') m6=m5.replace('=true ','T').replace('=false','F') let m6 build Box03 html truth table, compare with m5 carry true/false to eval(). Box04,05,02 text truth table use m5. See docC437, ans0 is text truth table. m2[i0] build by m5 '=true ' or '=false'. 2013-01-22-12-05 stop
<a name="docC401"> 2013-01-22-13-46 start Next for(j0) inside for(i0=0;i0<eL;i0++) for(j0=0;j0<m1;j0++) { //a112041740 //m5=2*(j0%period0)/(period0)<1?'=true ':'=false'; //a201042010 change to next m5=2*(j0%period0)/(period0)<1?T01:F01; Assume T01='=true ' and F01='=false' for T/F out put (not 0/1 output) Assume input equation is P∨Q∧R ---eq.A7a then eL=3 and m1=8 <a name="docC402">
P∨Q∧R for(i0){for(j0){...}} loops
i0 col
j0 row
j0=0TTT true
j0=1TTF false
j0=2TFT true
j0=3TFF false
j0=4FTT true
j0=5FTF false
j0=6FFT false
j0=7FFF false
Table width:
<a name="docC403"> Code line for(i0=0;i0<eL;i0++) { //a112041541 period0=Math.pow(2,eL-i0); //a112041931 m5=m6=''; //a112042335 for(j0=0;j0<m1;j0++) { //a112041740 m5=2*(j0%period0)/(period0)<1?T01:F01; ..... } } for(i0) loop scan table columns. i0=0:P col.; i0=1:Q col.; i0=2:R col. for(j0) loop scan table rows. j0=0: T,T,T row, j0=1: T,T,F row, ..... j0=6: F,F,T row, j0=7: F,F,F row. For a given i0,j0 value, program work in just one cell in table. <a name="docC404"> second explanation For i0=0,j0=1 we should get P=true P column value period 8. Code line m5=2*(j0%period0)/(period0)<1?T01:F01; say calculate 2*(j0%period0)/(period0) see whether its value is less than 1? If yes let m5=T01, otherwise m5=F01. Please review remainder operator %. Equation has a "2*" it is just a scale factor. Without "2*" evaluation criteria change from "<1?" to "<0.5?" "2*" is not a big deal, "<1?" is handier. <a name="docC405"> Given i0=0 and vary j0, there are eight combination, next calculate four of them. For i0=0,j0=1, 2*(j0%period0)/(period0) is 2*(1%8)/8=2*1/8=0.25 < 1 be true For i0=0,j0=1 m5='=true'. For i0=0,j0=3, 2*(j0%period0)/(period0) is 2*(3%8)/8=2*3/8=0.75 < 1 be true For i0=0,j0=3 m5='=true'. <a name="docC406"> For i0=0,j0=4, 2*(j0%period0)/(period0) is 2*(4%8)/8=2*4/8=1.0 < 1 be false For i0=0,j0=4 m5='=false'. For i0=0,j0=7, 2*(j0%period0)/(period0) is 2*(7%8)/8=2*7/8=1.75 < 1 be false For i0=0,j0=7 m5='=false'. <a name="docC407"> Given i0=1 and vary j0, next calculate four of them. Q column value period 4 For i0=1,j0=1, 2*(j0%period0)/(period0) is 2*(1%4)/4=2*1/4=0.5 < 1 be true For i0=1,j0=1 m5='=true'. For i0=1,j0=3, 2*(j0%period0)/(period0) is 2*(3%4)/4=2*3/4=1.5 < 1 be false For i0=1,j0=3 m5='=false'. <a name="docC408"> For i0=1,j0=4, 2*(j0%period0)/(period0) is 2*(4%4)/4=2*0/4=0.0 < 1 be true For i0=1,j0=4 m5='=true'. For i0=1,j0=7, 2*(j0%period0)/(period0) is 2*(7%4)/4=2*3/4=1.5 < 1 be false For i0=1,j0=7 m5='=false'. Given i0=2 and vary j0, calculate the true/false for R column leave to reader. 2013-01-22-14-57 stop <a name="docC409"> Scale every remainder to two! 2013-01-23-05-52 insert start Now analysis next equation again. m5=2*(j0%period0)/(period0)<1?T01:F01; This equation generate docC402 truth table P,Q,R column T/F value. Why it work this way? Let us go step by step. Here write P∨Q∧R truth table horizontal for easier explanation. j0=0 1 2 3 4 5 6 7 P: T T T T F F F F i0=0 Q: T T F F T T F F i0=1 R: T F T F T F T F i0=2 <a name="docC410"> The center part of generating equation is (j0%period0)/(period0) where period0=Math.pow(2,eL-i0); First step drop "/(period0)", keep only (j0%period0). Why? because (j0%period0) works! but poorly! Attention period0=Math.pow(2,eL-i0); (j0%period0) is function of i0 and j0. Given i0 and j0, determine (j0%period0) <a name="docC411"> For P column, period=8, red 0 to 7. j0=0 1 2 3 4 5 6 7 P: T T T T F F F F i0=0 re 0 1 2 3 4 5 6 7 're' is remainder operation % output row. compare reminder 0 1 2 3 4 5 6 7 with true/false T T T T F F F F write down a rule: for i0=0, P column, remainder = 0 1 2 3 assign P=True remainder = 4 5 6 7 assign P=False <a name="docC412"> For Q column, period=4 red 0 to 3. j0=0 1 2 3 4 5 6 7 Q: T T F F T T F F i0=1 re 0 1 2 3 0 1 2 3 compare reminder 0 1 2 3 0 1 2 3 with true/false T T F F T T F F write down a rule: for i0=1, Q column, remainder = 0 1 assign Q=True remainder = 2 3 assign Q=False <a name="docC413"> For R column, period=2 red 0 to 1. j0=0 1 2 3 4 5 6 7 R: T F T F T F T F i0=2 re 0 1 0 1 0 1 0 1 compare reminder 0 1 0 1 0 1 0 1 with true/false T F T F T F T F write down a rule: for i0=2, R column, remainder = 0 assign R=True remainder = 1 assign R=False <a name="docC414"> Good news ! This rule work perfect for any 3 variables logic equation. not two, not four. But what happen if we have an equation with 4 variables? Build 4V rule as next Assume equation has A,B,C,D 4 variables for A column, remainder = 0 to 7 assign A=True remainder = 8 to 15 assign A=False <a name="docC415"> for B column, remainder = 0 to 3 assign B=True remainder = 4 to 7 assign B=False for C column, remainder = 0 or 1 assign C=True remainder = 2 or 3 assign C=False for D column, remainder = 0 assign D=True remainder = 1 assign D=False This rule work perfect for any 4 variables logic equation. not three, not five. <a name="docC416"> So far so good. logictt2.htm allow equation contain logic variable up to 26. What happen if a naughty equation contain 26 variables? What is that rule? Collapse !! <a name="docC417"> There is an easy solution, which take care of any number variables, include 26 variables The answer is normalization. Scale every remainder to one! later, Scale every remainder to two! In this case, we need put "/(period0)" back use (j0%period0)/(period0) Let us exam the normalized version of above P,Q,R example. <a name="docC418"> For P column, period = red 0 to 7. j0=0 1 2 3 4 5 6 7 P: T T T T F F F F i0=0 re 0 1 2 3 4 5 6 7 're' is remainder operation % output row. period0=8 for 2^3=8 normalized re. 0/8 1/8 2/8 3/8 4/8 5/8 6/8 7/8 P true/false T T T T F F F F write down a rule: for i0=0, P column, normalized re. in [0, 0.5) assign P=True normalized re. in [0.5, 1) assign P=False <a name="docC419"> For Q column, period = red 0 to 3. j0=0 1 2 3 4 5 6 7 Q: T T F F T T F F i0=1 re 0 1 2 3 0 1 2 3 period0=4 for 2^2=4 normalized re. 0/4 1/4 2/4 3/4 0/4 1/4 2/4 3/4 Q true/false T T F F T T F F write down a rule: for i0=1, Q column, normalized re. in [0, 0.5) assign Q=True normalized re. in [0.5, 1) assign Q=False <a name="docC420"> For R column, period = red 0 to 1. j0=0 1 2 3 4 5 6 7 R: T F T F T F T F i0=2 re 0 1 0 1 0 1 0 1 period0=2 for 2^1=2 normalized re. 0/2 1/2 0/2 1/2 0/2 1/2 0/2 1/2 R true/false T F T F T F T F write down a rule: for i0=2, R column, normalized re. in [0, 0.5) assign R=True normalized re. in [0.5, 1) assign R=False <a name="docC421"> Pay attention to three new rules, they are the same. normalized re. in [0, 0.5) assign X=True normalized re. in [0.5, 1) assign X=False Even extend to 26 variables, still same rule !! Above explained (j0%period0)/(period0) "2*" in code equation m5=2*(j0%period0)/(period0)<1?T01:F01; scale rule to normalized remainder in [0, 1) assign X=True normalized remainder in [1, 2) assign X=False 2013-01-23-07-04 insert stop
<a name="docC422"> 2013-01-22-16-43 start if(tf10==1) //output 0/1 //a201042008 m6=m5.replace('=true ','1').replace('=false','0') else //output T/F m6=m5.replace('=true ','T').replace('=false','F') m2[j0]+=elemStr.charAt(i0) +m5 //a112041942 +',' Here is inside for(i0){for(j0){...}}. m5 has true/false value and apply to eval(), also to text truth table. m6 has T/F or 0/1 value apply to html table code. Decide m6 from m5. <a name="docC423"> what is m2[]? m2A,m2B Code line m2[j0]+=elemStr.charAt(i0)+m5+',' build m2[] array. If input equation is P∨Q∧R ---eq.A7a then elemStr has value 'PQR'. i0 step over elemStr='PQR'. <a name="docC424"> If i0=0, elemStr.charAt(i0)='P' If i0=j0=0, m5='=true', then m2[j0]+=elemStr.charAt(i0)+m5+',' is m2[0]+='P'+'=true'+','; Net result is m2[0]+='P=true,'; i0 move to 1 add Q m2[0]='P=true,Q=true,'; i0 to 2 add R m2[0]='P=true,Q=true,R=true,' Later code eval(m2[i0]+oneLine) which is eval('P=true,Q=true,R=true,(PandQ(PiorQ(P,Q),R))') give us symbolic equation T/F answer.
<a name="docC425"> if(tbCode) { //m6=m5.replace('=true ','T').replace('=false','F') tbArr[i0][j0]='<td>'+m6+'</td>';//a112050721 } //if(tbCode) } //for(j0=0;j0<m1;j0++) } //for(i0=0;i0<elemStr.length;i0++) if(tbCode) build html truth table output to Box03. If Box03 is defined, enter if() Code line tbArr[i0][j0]='<td>'+m6+'</td>'; store 'T' or 'F' or '1' or '0' to cell at [i0][j0]. i0 th column, j0 th row. m6 is special made for html table output. m5 is for eval() evaluation. See docC399 Usually 2D array has arr[row][col]. Above code build tbArr[i0][j0]=tbArr[col][row]. Here close for(i0) loop, close for(j0) loop. <a name="docC426"> To build Box03 html table code, use tbArr[][] and use tbStr0. tbArr[][] is two dimensional array of strings tbStr0 is a string, not array at all. tbArr is declared one and two dimensional at docC384 tbStr0 is declared a string at docC375 tbArr[][] is auxiliary variable. tbArr[][] build tbStr0 for(j0=0;j0<eL;j0++) tbStr0+=tbArr[j0][i0]; right below. tbStr0 is final table code string save to Box03. See future code boxc03.value=tbStr0;
<a name="docC427"> var eqTF=[]; //equation True/False for(i0=0;i0<m2.length;i0++) //a201222003 eqTF[i0]=eval(m2[i0]+oneLine); 'eqTF' mean EQuation True False value. Code line eqTF[i0]=eval(m2[i0]+oneLine) record symbolic equation true false value to i0 th cell of array eqTF. When write html table code use eqTF[] value once. When write text table code use eqTF[] value again. Avoid evaluate same thing twice. Early uploaded logictt2.htm evaluate same thing twice. Improvement made on 2013-01-22-20-03 = a201222003
<a name="docC428"> Above if(tbCode) build html table i0 th column, j0 th row elements. Next if(tbCode) build html table main body. var tf; //a201042021 var lineAns0=[]; //a201071144 var lA=0; if(tbCode) { for(i0=0;i0<m1;i0++) { tbStr0+='<tr>' //'<tr>' start a row for(j0=0;j0<eL;j0++) tbStr0+=tbArr[j0][i0]; //a112050732 //<a name="docC429"> tf=eqTF[i0]+''; //a201222016 change Boolean to string if(tf10==1) //output 0/1 //a201042022 tf=tf.replace('true','1').replace('false','0') lineAns0[lA++]=tf; //a201071145 tbStr0+='<td> </td>' tbStr0+='<td>'+tf+'</td>' //a201042025 use tf tbStr0+='</tr>\n'; //a112050728 '</tr>' end a row } //for(i0=0;i0<eL;i0++) <a name="docC430"> Code line var tf; declare variable tf. tf record symbolic equation's final true/false value. Related code is tf=eqTF[i0]+''; Any type data (include Boolean) add a string (even if empty '') to it, then whole thing convert to string. eval(m2[i0]+oneLine) return a Boolean value. eqTF[i0] store Boolean true/false. " eqTF[i0]+'' " is string, then tf=string, tf is string true/false. <a name="docC431"> Code line var lineAns0=[]; var lA=0; declare lineAns0 be an array. lA is index in lineAns0[lA], see lineAns0[lA++]=tf; Table output answer T/F vertically. If user want to compare two answers of same equation, again if equation has 6 or more variables. Compare 64,128 ... vertical T/F? That may burn one's eye. <a name="docC432"> logictt2.htm logictt4.htm logicmr2.htm has a one line box record T/F answer in row form, compare two answers with written code, it is one click easy job. If input equation is P∨Q∧R ---eq.A7a lineAns0[] has an array value [true,false,true,false,true,false,false,false] Program change lineAns0[] array value to T,F,T,F,T,F,F,F then send 'T,F,T,F,T,F,F,F' to one line box on web page. <a name="docC433"> If input equation is P∨Q∧R ---eq.A7a eL=3 and m1=8 which apply to next loops. Code line for(i0=0;i0<m1;i0++) { tbStr0+='<tr>' for(j0=0;j0<eL;j0++) tbStr0+=tbArr[j0][i0]; ..... tbStr0+='<td> </td>' tbStr0+='<td>'+tf+'</td>' tbStr0+='</tr>\n'; } build html truth table. <a name="docC434"> Assume i0=0, above for(i0) loop build first row of html table tbStr0+='<tr>' +'<td>T</td>'+'<td>T</td>'+'<td>T</td>' +'<td> </td>'+'<td>true</td>'+'</tr>' Bold red line produced by bold red for(j0) loop code. In for(j0) loop use tbStr0+=tbArr[j0][i0]; //because, here is not tbStr0+=tbArr[i0][j0]; //tbArr[col][row] Bold blue section produced by bold blue +tf+ line. tf=eqTF[i0]=eval(m2[i0]+oneLine) tf is symbolic equation true/false value. 2013-01-22-19-03 stop
<a name="docC435"> 2013-01-22-22-01 start tbStr0+='</table>\n' +'Table width: ' +'<input id='+boxID+' value='+default500+' size=5 ' +'onchange="'+tblID+'.width='+boxID+'.value" /> ' +'<INPUT type="button" value="default" ' +'onclick="'+boxID+'.value='+default500+'; ' +tblID+'.width='+boxID+'.value ">\n' boxc03.value=tbStr0; //a112042341 } //if(tbCode) <a name="docC436"> This code section is html truth table end part. Build table width control box. tblID and boxID each has same 20 random ID number, make sure different from other html truth table ID. Table string save to Box03 let user copy and paste to user's own web page.
<a name="docC437"> if(tf10==0) //output T/F //a201042034 { ans0=oneLin0+'\n' for(i0=0;i0<m2.length;i0++) ans0+=m2[i0]+' '+eqTF[i0]+'\n'; //a201222017 eqTF[] if(typeof(chkbxA01)=='object' &&!chkbxA01.checked) //a112161623 narrow output ans0=ans0.replace(/\=true ,/g,'t, ').replace(/\=false,/g,'f, '); if(typeof(lineAnswer)=='object') //a201071147 lineAnswer.value=(lineAns0+'').replace(/true/g,'T').replace(/false/g,'F'); //a201071213 return ans0; //a112041955 } //if(tf10==0) <a name="docC438"> If user choose output T/F (not 0/1), above is the final code. ans0 is text truth table (not html truth table) If input equation is P∨Q∧R ---eq.A7a text truth table is next <a name="docC439"> [[ P∨Q∧R P=true ,Q=true ,R=true , true P=true ,Q=true ,R=false, false P=true ,Q=false,R=true , true P=true ,Q=false,R=false, false P=false,Q=true ,R=true , true P=false,Q=true ,R=false, false P=false,Q=false,R=true , false P=false,Q=false,R=false, false (PandQ(PiorQ(P,Q),R)) ]] <a name="docC440"> Early version logictt2.htm accept only code equation "(PandQ(PiorQ(P,Q),R))" not symbolic "P∨Q∧R" Code line ans0=oneLin0+'\n' initialize ans0 to "(PandQ(PiorQ(P,Q),R))" not initialize to "P∨Q∧R". But output appear user input on top. This is the work of function runEqn(). <a name="docC441"> Code line for(i0=0;i0<m2.length;i0++) ans0+=m2[i0]+' '+eqTF[i0]+'\n'; build P=true ,Q=true ,R=true , true ..... P=false,Q=false,R=false, false line by line Red come from m2[i0]. Blue come from eqTF[i0] <a name="docC442"> If user unchecked box Text output [ ] narrow; Code line ans0=ans0.replace(/\=true ,/g,'t, ').replace(/\=false,/g,'f, '); is active, change "=true ," to "t, " and change "=false," to "f, " Similar change apply to line answer. Program send ans0 back to calling function. ans0 is user equation TEXT truth table.
<a name="docC443"> //above return T/F //below return 0/1 a201042035 ans0=oneLin0+'\n' for(i0=0;i0<m2.length;i0++) ans0+=m2[i0]+' '+eval(m2[i0]+oneLine)+'\n'; if(typeof(chkbxA01)=='object' &&!chkbxA01.checked) //a112161623 narrow output ans0=ans0.replace(/true /g,'1').replace(/false/g,'0').replace(/true/g,'1'); if(typeof(lineAnswer)=='object') //a201071147 lineAnswer.value=(lineAns0+'').replace(/true/g,'1').replace(/false/g,'0'); //a201071214 return ans0; //a201042037 } //function logic1Line(arg1) <a name="docC444"> If user choose output 0/1, this code section do the 0/1 job. Same reason as T/F output. function logic1Line(arg1) document is done. 2013-01-22-22-37 stop <a name="docC445"> 2013-01-23-10-32 Next is function logic1Line(arg1) in function document written on 2012-12-05-06-42 now 2013-01-23 move it to docC end one line before next document is code line var m0,m1,m2,m3,m4,m5,m6; This code line is still in function logic1Line(arg1) but no "what is m2[]? " document follow it. <a name="docC446"> 2012-12-05-06-42 start //a112050642 what is m2[]? see next example. PiffQ(notP(PiftQ(P,Q)),PandQ(P,notP(Q))) (~(P→Q))↔(P∧(~Q)) chapter01.pdf page 17/72 eq.1.5 //a112022039 <a name="docC447"> what is m2[]? m2A,m2C equation (~(P→Q))↔(P∧(~Q)) has P,Q two variables. elemStr='PQ' eL=elemStr.length=2 m1=Math.pow(2,eL)=pow(2,2)=4 m2=new Array(m1)=new Array(4) First iteration m2[] store [T,T,F,F] for P m2= ['P=true ,', 'P=true ,', 'P=false,', 'P=false,'] <a name="docC448"> Second iteration m2[] store [T,F,T,F] for Q m2= ['P=true ,Q=true ,', 'P=true ,Q=false,', 'P=false,Q=true ,', 'P=false,Q=false,'] <a name="docC449"> finally m2[] array each element add one equation string PiffQ(notP(PiftQ(P,Q)),PandQ(P,notP(Q))) m2= ['P=true ,Q=true ,PiffQ(notP(PiftQ(P,Q)),PandQ(P,notP(Q)))', 'P=true ,Q=false,PiffQ(notP(PiftQ(P,Q)),PandQ(P,notP(Q)))', 'P=false,Q=true ,PiffQ(notP(PiftQ(P,Q)),PandQ(P,notP(Q)))', 'P=false,Q=false,PiffQ(notP(PiftQ(P,Q)),PandQ(P,notP(Q)))'] m2[] has four elements, each element is a string. For example m2[0] has next line string 'P=true ,Q=true ,PiffQ(notP(PiftQ(P,Q)),PandQ(P,notP(Q)))' //above statement is not exact. //m2[0] has 'P=true ,Q=true ,' //call eval(m2[0]+'PiffQ(notP(PiftQ(P,Q)),PandQ(P,notP(Q)))') //is actual process. a202051708 <a name="docC450"> eval(m2[0]) become eval('P=true ,Q=true ,PiffQ(notP(PiftQ(P,Q)),PandQ(P,notP(Q)))') this code line get a true/false for compound statement. P=true comma Q=true comma PiffQ() is compound statement. <a name="docC451"> Second example (P→(Q∨R))↔((P→Q)∨(P→R)) This equation has P,Q,R three variables. elemStr='PQR' eL=elemStr.length=3 m1=Math.pow(2,eL)=pow(2,3)=8 m2=new Array(m1)=new Array(8) m2[] store [T,T,T,T,F,F,F,F] for P m2[] store [T,T,F,F,T,T,F,F] for Q m2[] store [T,F,T,F,T,F,T,F] for R <a name="docC452"> First iteration m2[] store [T,T,T,T,F,F,F,F] for P m2= ['P=true ,', 'P=true ,', 'P=true ,', 'P=true ,', 'P=false,', 'P=false,', 'P=false,', 'P=false,'] <a name="docC453"> Second iteration m2[] store [T,T,F,F,T,T,F,F] for Q m2= ['P=true ,Q=true ,', 'P=true ,Q=true ,', 'P=true ,Q=false,', 'P=true ,Q=false,', 'P=false,Q=true ,', 'P=false,Q=true ,', 'P=false,Q=false,', 'P=false,Q=false,'] <a name="docC454"> Third iteration m2[] store [T,F,T,F,T,F,T,F] for R m2= ['P=true ,Q=true ,R=true ,', 'P=true ,Q=true ,R=false,', 'P=true ,Q=false,R=true ,', 'P=true ,Q=false,R=false,', 'P=false,Q=true ,R=true ,', 'P=false,Q=true ,R=false,', 'P=false,Q=false,R=true ,', 'P=false,Q=false,R=false,'] <a name="docC455"> m2[] has eight elements, each element is a string. Attach compound equation code is same as first example. 2012-12-05-07-06 stop //a112050706
"proofread" 2012-12-20-11-18 done first proofread. 2012-12-23-17-50 done second proofread. 2013-01-06-18-58 done third proofread. 2013-01-20-18-13 done fourth proofread. first proofread function sym2fun1() doc 2013-01-25-15-48 done fifth proofread. first proofread function logic1Line() doc
<"binaryTotal"> ¬ ~ ∨ ⊻ ∧ → ← ↔ | ⊽ ⇒ ⇐ ⇔

<"sampleTable"> //a112231350 build three tables
Next is example 11, Box03 output. chapter01.pdf p.22/72 eq.1.28
PQR answer
TTT true
TTF true
TFT true
TFF true
FTT true
FTF false
FFT false
FFF false
Table width:
PQR answer
TTT true
TTF true
TFT true
TFF true
FTT true
FTF false
FFT false
FFF false
Table width:
PQR answer
TTT true
TTF true
TFT true
TFF true
FTT true
FTF true
FFT true
FFF true
Table width:
You can delete/move/change table top equation. Some equation is
wider than table. Move equation above/below table is a good idea.
If choose example 31, left equation is too long, need user modify.
Example 38 Box03 html output "Table width" change
from 250 to 350. Avoid two equations merge to one.
Copy Box03 html code paste to any html file,
save file and refresh page to see table.

Javascript index   local
Save graph code to same folder as htm files.   local

file name logictt2.htm mean
LOGIC Truth Table, English(2) .htm
Chinese version is logictt1.htm start up output to T/F , has document. start up output to 0/1 , no document.
First upload 2012-12-08 (logictt2_v07)

Thank you for visiting Freeman's page.
Freeman Liu,Hsinhan 劉鑫漢

Another better Truth Table Generator