File: misc.mac

package info (click to toggle)
maxima-sage 5.45.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 113,788 kB
  • sloc: lisp: 440,833; fortran: 14,665; perl: 14,369; tcl: 10,997; sh: 4,475; makefile: 2,520; ansic: 447; python: 262; xml: 59; awk: 37; sed: 17
file content (85 lines) | stat: -rw-r--r-- 2,842 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
These functions implement misc functions needed by Solver
Copyright (C) 2000 Dan Stanger

This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published
by the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.

This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

Dan Stanger dan.stanger@ieee.org
please contact me for updates to this code
*/

/******************************************************************************/
/* Powers creates a list of low powers in a variable                          */
/******************************************************************************/

Powers(e,v) :=
  if atom(e) then [lopow(e,v)]
  else if part(e,0)="+" or part(e, 0)="-" then
    maplist(lambda([p],lopow(p,v)), e)
  else
    [lopow(e,v)]$

/******************************************************************************/
/* pop pops the first element off a list and returns it                       */
/******************************************************************************/

Pop(l) ::= buildq([l],block([t:first(l)],l:rest(l),t))$

/******************************************************************************/
/* Set_Element modifies lists or matrixes and returns the list or matrix      */
/******************************************************************************/

Set_Element(o,i,j, [l]):=
  if matrixp(o) then (
    if l # [] then (
      o[i,j]:first(l),
      o
    )
    else (
      o[i]:j,
      o
    )
  )
  else (
    o[i]:j,
    o
  )$

EquationP(eq) := part(eq,0)="="$

/******************************************************************************/
/* Solver does not know maxima sets - workarounds for set functions.          */
/******************************************************************************/

Setify(lst) :=
  if length(lst)=0 then []
  else append([lst[1]], Setify(delete(lst[1], lst)))$

DisjointP(l1, l2) := disjointp(setify(l1), setify(l2))$

Intersection(l1, l2) :=
  if length(l1)=0 then []
  else if member(l1[1], l2) then append([l1[1]], Intersection(rest(l1), l2))
  else Intersection(rest(l1), l2)$

SetDifference(l1, l2) := listify(setdifference(setify(l1), setify(l2)))$

Union([l]) := lreduce(Union2, l)$

Union2(l1, l2) :=
  if length(l2)=0 then l1
  else if not(member(l2[1], l1)) then Union2(append(l1, [l2[1]]), rest(l2))
  else Union2(l1, rest(l2))$