Author Topic: Need Help Creating Truth Table Program for Nspire  (Read 13181 times)

0 Members and 1 Guest are viewing this topic.

Offline xacto

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +10/-0
    • View Profile
Need Help Creating Truth Table Program for Nspire
« on: October 11, 2013, 08:21:28 pm »
Does anyone know how or have any advice on how to create a program for the Nspire CX CAS that will generate truth tables based on a statement ex. "p V ~q ? Is it even possible? I am learning about logic in college and thought it would be helpful if I could check my calculator instead of writing things down every time. If it is possible, I want to make it capable of handling conditional statements as well as self-contradictions, tautologies, and implications. I'm not really sure how to use TI-BASIC on the Nspire, so any help or ideas whatsoever would be appreciated. Thanks.

Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: Need Help Creating Truth Table Program for Nspire
« Reply #1 on: October 12, 2013, 08:37:35 am »
Lua would be more suited than TI basic (which is quite limited on the Nspire). Other than that, programming logic is easy since programming /is/ logic.

Offline Loulou 54

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 165
  • Rating: +39/-0
    • View Profile
    • Mes programmes sur TI bank.
Re: Need Help Creating Truth Table Program for Nspire
« Reply #2 on: October 12, 2013, 02:26:26 pm »
Hello xacto !

Dou you know ABA Logique Nspire ? This is an helpful program I made that will perfectly suit your needs, about logic expression and Boole algebra !

It handles Truth tables and Karnaugh map, and you can even minimize expressions or check equivalence between two expressions. Note that the program is in french (as I am french..) and that the input is not in the same "format" as yours, with "^", "v" and "~" but with "*", "+" and "/" instead. (this format is more used in the industry and is easily to enter with a keyboard !)

So, go download it and try it ! If you need some translations or help, ask it just here ! ;)

NOTE : it doesn't work on OS 3.2 for now ! (But VERY soon !) Actually if you want a 3.2 working version, it's already done, but not realeased yet. I can join the file if you need it.
« Last Edit: October 12, 2013, 05:14:28 pm by Loulou 54 »
Some of my program available here.. :)
http://ti.bank.free.fr/index.php?mod=archives&ac=voir2&id=1471

     

Offline xacto

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +10/-0
    • View Profile
Re: Need Help Creating Truth Table Program for Nspire
« Reply #3 on: October 12, 2013, 04:57:55 pm »
Unfortunately, the computer with my TI Software on it has a virus so it's currently unstable. Also, in terms of Lua, I have no experience with it. Loulou 54, by any chance could I have the code for the truth table portion of your program? That way, I could paste it into an emulator and use it that way until my computer is up and running.
« Last Edit: October 12, 2013, 04:58:47 pm by xacto »

Offline Loulou 54

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 165
  • Rating: +39/-0
    • View Profile
    • Mes programmes sur TI bank.
Re: Need Help Creating Truth Table Program for Nspire
« Reply #4 on: October 12, 2013, 05:26:24 pm »
Err it's a bit complicated because it needs different part of the program. And most of them are in Lua.
If the Student Software isn't working, you can try the TI-Nspire Computer Software which is a simple link program. You can send the ABA Logique file on your calculator with it.

PS : actually, as ABA Logique was originally a Basic program for the TI 89, I first made a reduced Basic version of it for the Nspire. (despite the bad Basic of the Nspire) The truth table thing was working. I'll try to find the interesting parts for you and paste them here anyway.

But remind that ABA Logique provide a lot more functions and is really ergonomic ! ;)
Some of my program available here.. :)
http://ti.bank.free.fr/index.php?mod=archives&ac=voir2&id=1471

     

Offline Loulou 54

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 165
  • Rating: +39/-0
    • View Profile
    • Mes programmes sur TI bank.
Re: Need Help Creating Truth Table Program for Nspire
« Reply #5 on: October 12, 2013, 05:54:37 pm »
So here are the interesting extracts in Basic :

INPUT : a string in the following format :
example : eq:="a+/(b*/c)"
/!\ use only letters between "a" and "f".

* Formating into a boolean expression : (with "and", "or", "1-" for not)

inString(eq,"*")→tr:While tr≠0:left(eq,tr-1)&" and "&right(eq,dim(eq)-tr)→eq:inString(eq,"*",tr)→tr:EndWhile::inString(eq,"+")→tr:While tr≠0:left(eq,tr-1)&" or "&right(eq,dim(eq)-tr)→eq:inString(eq,"+",tr)→tr:EndWhile::inString(eq,"//")→tr:While tr≠0:left(eq,tr-1)&mid(eq,tr+2)→eq:inString(eq,"//",tr)→tr:EndWhile::inString(eq,"/")→tr:While tr≠0:left(eq,tr-1)&"1-"&right(eq,dim(eq)-tr)→eq:inString(eq,"/",tr)→tr:EndWhile

* Building the list of the involved variables :

{}→v:{}→vv:For aba,1,8:If inString(eql,char(aba+96))≠0 Then:augment(v,{char(aba+96)})→v:augment(vv,{aba+96})→vv:EndIf:EndFor

* Building the natural truth table :

Disp " ★ Table de vérité (naturel)":newMat(2^(dim(v))+1,dim(v)+1)→tb:"S="→tb[1,dim(v)+1]:For aba,1,dim(v):v[aba]→tb[1,aba]:EndFor::For aba,0,2^(dim(v))-1:setMode(7,3):mid(string(aba),3)→n:setMode(7,1):While dim(n)≠dim(v):"0"&n→n:EndWhile:For cpt,1,dim(v):expr(mid(n,cpt,1))→#(v[cpt]):#(v[cpt])→tb[aba+2,cpt]:EndFor:expr(eq)→tb[aba+2,dim(v)+1]:EndFor::Disp tb

* Building the gray truth table : (reflected binary coding)

{0,1,2,1,3,1,2,1,4,1,2,1,3,1,2,1,5,1,2,1,3,1,2,1,4,1,2,1,3,1,2,1,6,1,2,1,3,1,2,1,4,1,2,1,3,1,2,1,5,1,2,1,3,1,2,1,4,1,2,1,3,1,2,1}→chg
Disp " ★ Table de vérité (Gray)":newMat(2^(dim(v)),dim(v)+1)→tbg::For aba,1,dim(v):0→#(v[aba]):EndFor::For aba,1,2^(dim(v)):If aba≠1:1-expr(v[dim(v)+1-chg[aba]])→#(v[dim(v)+1-chg[aba]]):For cp,1,dim(v):expr(v[cp])→tbg[aba,cp]:EndFor:expr(eq)→tbg[aba,dim(v)+1]:EndFor::newMat(1,dim(v)+1)→t:"S="→t[1,dim(v)+1]:For aba,1,dim(v):v[aba]→t[1,aba]:EndFor::Disp colAugment(t,tbg)


NOTE : if you're under OS 3.2 there are risks it doesn't work ! (TI has changed some things about boolean operators. Especially, they added the logical => and <=>. I don't know why, but using the boolean operators with 0 and 1 wasn't always working through Lua. That's why I had to replace all the calculations using "false" and "true" statements. Anyway, try it first !)
« Last Edit: October 12, 2013, 05:56:12 pm by Loulou 54 »
Some of my program available here.. :)
http://ti.bank.free.fr/index.php?mod=archives&ac=voir2&id=1471

     

Offline xacto

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +10/-0
    • View Profile
Re: Need Help Creating Truth Table Program for Nspire
« Reply #6 on: October 12, 2013, 06:06:59 pm »
Woah, I see what you mean. And of course, I just happen to be graced without OS 3.2 and with Ndless (Thank God) That being the case, are there any commands in BASIC that would allow me add the list in column one to the list in column two? *Considering 0=true and 1=false* Then based on whether the sum of the two list is 0, 1, or 2, Display true or false? I'm guessing I would probably have to set parameters to distinguish between AND and OR too... I'll look for and download the TI-Nspire Computer Software so I can try that also.
« Last Edit: October 12, 2013, 06:08:53 pm by xacto »

Offline Loulou 54

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 165
  • Rating: +39/-0
    • View Profile
    • Mes programmes sur TI bank.
Re: Need Help Creating Truth Table Program for Nspire
« Reply #7 on: October 12, 2013, 07:02:19 pm »
Ok I see. Yeah it's a good idea, but then you have to find a way to evaluate the expressions..

Me, (I have not clearly explained) I'm using the boolean evaluation of the calculator on 0 and 1. Like this :
a+/(b*/c) => a or 1-(b and 1-c)
and then I affect every value to a,b,c and calculate it.

Your solution may be cool also, and maybe more efficient.
Maybe we could do so :
a:={0,0,0,0,1,1,1,1}
b:={0,0,1,1,0,0,1,1}
c:={0,1,0,1,0,1,0,1}
and replace :
"a*b" => a*b
"a+b" => ceiling((a+b)/2)
"/a" => (1-a)

but then, when you'll have to evaluate a complex equation, you'll have to place some extra parenthesis at the right position.
The best way to handle this is to do it recursively. Moreover, the TI-Basic "part(" function, may help you a lot to determine both argument of a binary operator :
example : evaluate(a+b*c)
part(a+b*c,0) ==> "+" the operator with the priority
part(a+b*c,1) ==>a first part
part(a+b*c+c,2) ==>b*c second part

so you know you have to do : ceiling((evaluate(a)+evaluate(b*c))/2)
- evaluate(a) will return a
- evaluate(b*c) will return evaluate(b)*evaluate(c)
     evaluate(b) will return b
     evaluate(c) will return c


Well, as you like ! ^^ Good luck anyway !
« Last Edit: October 12, 2013, 07:08:53 pm by Loulou 54 »
Some of my program available here.. :)
http://ti.bank.free.fr/index.php?mod=archives&ac=voir2&id=1471

     

Offline xacto

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +10/-0
    • View Profile
Re: Need Help Creating Truth Table Program for Nspire
« Reply #8 on: October 12, 2013, 10:35:26 pm »
Well then, I guess I'm off to learn how to use binary then. It's unfortunate that I know so little of the Nspire CX BASIC language, but I'll get the basics down after a little while. Thanks Loulou 54! I'll let you know if I make any progress.
« Last Edit: October 12, 2013, 10:35:55 pm by xacto »

Offline Loulou 54

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 165
  • Rating: +39/-0
    • View Profile
    • Mes programmes sur TI bank.
Re: Need Help Creating Truth Table Program for Nspire
« Reply #9 on: October 14, 2013, 07:20:18 pm »
Ok let me know, good luck ! :)
Some of my program available here.. :)
http://ti.bank.free.fr/index.php?mod=archives&ac=voir2&id=1471