home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.yorku.ca 2015 / ftp.cs.yorku.ca.tar / ftp.cs.yorku.ca / pub / peter / SVT / SWI / simplify.pl < prev    next >
Text File  |  2007-02-25  |  2KB  |  59 lines

  1. /*
  2.  
  3.   SIMPLIFY
  4.  
  5. copyright  P. H. Roosen-Runge, October 1992, 1997
  6. %=====================================================
  7. %      1.3.1 July 8: expects rules to be loaded from theory files
  8. %                rather than the file simplification rules.
  9. %                Rules can be asserted interactively.
  10. %      1.4   Nov. 30, 1997: rename any Prolog variables in result
  11. %      1.4.2SWI   January 6, 2007: SWI Prolog version
  12. %=====================================================
  13.   The program 'simplify' uses the predicate simplify/2 found in 
  14.   /cs/fac/src/SVT-lib/simp.pl to simplify terms read from the standard input, 
  15.   using simplification rules loaded from theory modules such arithmetic.simp.
  16.  
  17.   theory files are loaded by including 
  18.       theory('<file specification>').
  19.   in the  input data.
  20.  
  21. */
  22.  
  23. % :- no_style_check(single_var). 
  24. % not in SWI. Use style_check(-singleton) if needed.
  25.  
  26. :- fileerrors(_, off).
  27. :- multifile '->>'/2.
  28. :- dynamic '->>'/2.      % so rules can be asserted interactively.
  29.  
  30. % use .plrc for paths.
  31. :- ensure_loaded(lib('simp.pl')).  % simplify/2 and canonical/2
  32.  
  33. % user_error_handler(_,_,_,_) :-  error('!! Something wrong.').
  34. % error(X) :- write('!! '), write(X), nl. 
  35.  
  36. activate :- 
  37.  write('Version 1.4.2SWI, January 6, 2007')
  38.      , nl,
  39.        simplifyTerms
  40.      ;
  41.      nl, write('!! Something wrong.'), nl, halt.
  42.  
  43. simplifyTerms :- read(T),
  44.       (T==end_of_file, halt
  45.       ;
  46.        (T = theory(File) -> theory(File)
  47.            ;
  48.             T = assert((Rule)) -> addRule((Rule))
  49.        ;
  50.         simplify(T, Result), 
  51.         copy_term(T ->> Result, Pretty),
  52.             numbervars(Pretty, 0, _),    Pretty = (PT ->> PR),
  53.             nl, write(PT), write(' ->> '),
  54.             nl, write('   '), write(PR), nl
  55.        ),
  56.        simplifyTerms, nl
  57.       ).
  58.  
  59.