We take two tcl access scripts, presuming presence of Maxima and PostgreSQL on a system or in the latter case on some system in the network:

 proc domaxima { {m} } {
    set t "display2d:false;\n$m;"
    # return [string range [exec maxima << $t | tail -2  ] 6 end-7]
    return [string range [exec maxima -q << $t ] 32 end-7]
    #return [exec maxima --real-quiet << $t ]
 }

 proc dosql {s} {
  global db
   if {[catch {pg_exec $db $s} reply]} {
      puts "sql error : $reply,[pg_result $reply -error]"
      return "Error"
   }
   if {[pg_result $reply -status] == "PGRES_COMMAND_OK"} {
      return {}
   }
   if {[pg_result $reply -status] != "PGRES_TUPLES_OK"} {
      puts "sql error: [pg_result $reply -error]"
      return "Error"
   }
   return [pg_result $reply -llist]
 #   pg_result $reply -clear
   return 
 }

 # You could use another with similar results, it appears:
 package require pgintcl
 # connect to your sql server:
 set db [pg_connect -conninfo [list host = 192.168.0.1 user = zxy dbname = somedb password = 0x987654]]

 # Now create a table for formulas
 dosql "create table formula (f varchar(256))"

Now we can try to make a nice database with formulas:

 dosql "insert into formula values ([pg_quote "x^2"])"
 dosql "insert into formula values ([pg_quote "x^3"])"

But we can also use maxima to help us, for instance the optimizer will reorder terms and at request also simplify so we can keep formulas unique for instance:

 dosql "insert into formula values ([pg_quote [domaxima "x^4"]])"
 dosql "insert into formula values ([pg_quote [domaxima "x^3"]])"

Now lets look at the nice lil' list of math work:

 foreach i [dosql "select distinct f from formula"] {puts |$i}
  |x^2
  |x^3
  |x^4

enter categories here