-
Notifications
You must be signed in to change notification settings - Fork 0
/
approx-alike.lisp
65 lines (49 loc) · 2.12 KB
/
approx-alike.lisp
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
(in-package :maxima)
;; This is version of approx-alike that applies `resimplify` and `ratsimp` to each
;; input at the top level. This version helps find testsuite failures that are
;; purely syntatic. It is *not* intended to be a replacment to the standard
;; version of approx-alike.
;; If a test fails using the standard approx-alike and passes using this version,
;; it might mean that Maxima is incorrectly returing an unsimplified result.
(defun approx-alike (f g)
(or (approx-alike-h f g)
(approx-alike-h (resimplify f) (resimplify g))
(let (($keepfloat t))
(approx-alike-h (sratsimp (resimplify f))
(sratsimp (resimplify g))))
(let (($keepfloat t))
(approx-alike-h ($factor ($expand f))
($factor ($expand g))))))
(defun approx-alike-h (f g)
(cond ((floatp f) (and (floatp g) ($float_approx_equal f g)))
(($bfloatp f) (and ($bfloatp g) ($bfloat_approx_equal f g)))
(($taylorp g)
(approx-alike 0 (sub (ratdisrep f) (ratdisrep g))))
((stringp f)
(and (stringp g) (string= f g)))
((arrayp f)
(and (arrayp g)
(equal (array-dimensions f) (array-dimensions g))
(approx-alike ($listarray f) ($listarray g))))
((hash-table-p f)
(and (hash-table-p g) (approx-alike ($listarray f) ($listarray g))))
((atom f)
(and (atom g) (equal f g)))
((op-equalp f 'lambda)
(and (op-equalp g 'lambda)
(approx-alike-list (mapcar #'(lambda (s) (simplifya s nil)) (margs f))
(mapcar #'(lambda (s) (simplifya s nil)) (margs g)))))
(($ratp f)
(and ($ratp g) (approx-alike (ratdisrep f) (ratdisrep g))))
;; maybe we don't want this.
((op-equalp f 'mquote)
(approx-alike (second f) g))
;; I'm pretty sure that (mop f) and (mop g) won't signal errors, but
;; let's be extra careful.
((and (consp f) (consp (car f)) (consp g) (consp (car g))
(or (approx-alike (mop f) (mop g))
(and (symbolp (mop f)) (symbolp (mop g))
(approx-alike ($nounify (mop f)) ($nounify (mop g)))))
(eq ($subvarp f) ($subvarp g))
(approx-alike-list (margs f) (margs g))))
(t nil)))