dint.red 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. module dint; % Definite integration support.
  2. % Author: Anthony C. Hearn.
  3. fluid '(!*precise);
  4. symbolic procedure simpdint u;
  5. begin scalar low,upp,fn,var,x,y;
  6. if length u neq 4
  7. then rerror(int,2,"Improper number of arguments to INT");
  8. fn := car u;
  9. var := cadr u;
  10. low := caddr u;
  11. upp := cadddr u;
  12. low := reval low;
  13. upp := reval upp;
  14. if low = upp then return nil ./ 1
  15. else if null getd 'new_defint then nil
  16. else if upp = 'infinity
  17. then if low = 0
  18. then if not smemql('(infinity unknown),
  19. x := defint!* {fn,var})
  20. then return simp!* x else nil
  21. else if low = '(minus infinity)
  22. then return mkinfint(fn,var)
  23. else if freeof(var,low)
  24. then if not smemql('(infinity unknown),
  25. x := defint!* {fn,var})
  26. and not smemql('(infinity unknown),
  27. y := indefint!* {fn,var,low})
  28. then return simp!* {'difference,x,y} else nil
  29. else nil
  30. else if upp = '(minus infinity) or low = 'infinity
  31. then return negsq simpdint {fn,var,upp,low}
  32. else if low = '(minus infinity)
  33. then return
  34. simpdint{prepsq simp{'sub,{'equal,var,{'minus,var}},fn},
  35. var,{'minus,upp},'infinity}
  36. else if low = 0
  37. then if freeof(var,upp)
  38. and not smemql('(infinity unknown),
  39. x := indefint!* {fn,var,upp})
  40. then return simp!* x else nil
  41. else if freeof(var,upp) and freeof(var,low)
  42. and not smemq('(infinity unknown),
  43. x := indefint!* {fn,var,upp})
  44. and not smemql('(infinity unknown),
  45. y := indefint!* {fn,var,low})
  46. then return simp!* {'difference,x,y};
  47. return mkdint(fn,var,low,upp)
  48. end;
  49. symbolic procedure defint!* u;
  50. (if errorp x then 'unknown else car x)
  51. where x = errorset2 {'new_defint,mkquote u};
  52. symbolic procedure indefint!* u;
  53. (if errorp x or eqcar(car x,'indefint2) then 'unknown else car x)
  54. where x = errorset2 {'new_indefint,mkquote u};
  55. symbolic procedure mkdint(fn,var,low,upp);
  56. % This could be used as an entry point to other dint procedures.
  57. % Should we handle infinity, - infinity differently?
  58. begin scalar x; % ,!*precise;
  59. if getd 'defint0
  60. and not((x := defint0 {fn,var,low,upp}) eq 'failed)
  61. then return simp x
  62. else if not smemq('infinity,low) and not smemq('infinity,upp)
  63. then <<x := prepsq!* simpint {fn,var};
  64. if not eqcar(x,'int)
  65. then return simp!* {'difference,
  66. subeval {{'equal,var,upp},x},
  67. subeval {{'equal,var,low},x}}>>;
  68. return mksq({'int,fn,var,low,upp},1)
  69. end;
  70. symbolic procedure mkinfint(fn,var);
  71. begin scalar x,y;
  72. if getd 'defint0
  73. and not((x := defint0 {fn,var,'(minus infinity),'infinity})
  74. eq 'failed) then return simp x;
  75. x := simpdint {fn,var,0,'infinity};
  76. y := simpdint {fn,var,'(minus infinity),0};
  77. if kernp x and eqcar(mvar numr x,'int)
  78. and kernp y and eqcar(mvar numr y,'int)
  79. then return mkdint(fn,var,'(minus infinity),'infinity)
  80. else return addsq(x,y)
  81. end;
  82. endmodule;
  83. end;