...
 
Commits (3)
......@@ -847,11 +847,13 @@
(and (eq calc-angle-mode 'rad)
(let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi))))
(and n
(math-div 1 (math-known-sin (car n) (nth 1 n) 120 300)))))
(let ((s (math-known-sin (car n) (nth 1 n) 120 300)))
(and s (math-div 1 s))))))
(and (eq calc-angle-mode 'deg)
(let ((n (math-integer-plus (nth 1 math-simplify-expr))))
(and n
(math-div 1 (math-known-sin (car n) (nth 1 n) '(frac 2 3) 300)))))
(let ((s (math-known-sin (car n) (nth 1 n) '(frac 2 3) 300)))
(and s (math-div 1 s))))))
(and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin)
(math-div
1
......@@ -872,11 +874,13 @@
(and (eq calc-angle-mode 'rad)
(let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi))))
(and n
(math-div 1 (math-known-sin (car n) (nth 1 n) 120 0)))))
(let ((s (math-known-sin (car n) (nth 1 n) 120 0)))
(and s (math-div 1 s))))))
(and (eq calc-angle-mode 'deg)
(let ((n (math-integer-plus (nth 1 math-simplify-expr))))
(and n
(math-div 1 (math-known-sin (car n) (nth 1 n) '(frac 2 3) 0)))))
(let ((s (math-known-sin (car n) (nth 1 n) '(frac 2 3) 0)))
(and s (math-div 1 s))))))
(and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin)
(math-div 1 (nth 1 (nth 1 math-simplify-expr))))
(and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arccos)
......@@ -977,11 +981,13 @@
(and (eq calc-angle-mode 'rad)
(let ((n (math-linear-in (nth 1 math-simplify-expr) '(var pi var-pi))))
(and n
(math-div 1 (math-known-tan (car n) (nth 1 n) 120)))))
(let ((tn (math-known-tan (car n) (nth 1 n) 120)))
(and tn (math-div 1 tn))))))
(and (eq calc-angle-mode 'deg)
(let ((n (math-integer-plus (nth 1 math-simplify-expr))))
(and n
(math-div 1 (math-known-tan (car n) (nth 1 n) '(frac 2 3))))))
(let ((tn (math-known-tan (car n) (nth 1 n) '(frac 2 3))))
(and tn (math-div 1 tn))))))
(and (eq (car-safe (nth 1 math-simplify-expr)) 'calcFunc-arcsin)
(math-div (list 'calcFunc-sqrt
(math-sub 1 (math-sqr (nth 1 (nth 1 math-simplify-expr)))))
......
......@@ -2417,6 +2417,12 @@
((= (length math-t1) 2)
(apply 'math-solve-linear
(car math-t2) math-try-solve-sign math-t1))
((= (length math-t1) 1)
;; Constant polynomial.
(if (eql (nth 2 math-t2) 1)
nil ; No possible solution.
;; Root of the factor, if any.
(math-try-solve-for (nth 2 math-t2) 0 nil t)))
(math-solve-full
(math-poly-all-roots (car math-t2) math-t1))
(calc-symbolic-mode nil)
......
......@@ -2597,7 +2597,7 @@ It must return a string."
search-string (nth (if replaced 4 3) elt)
last-replacement (nth (if replaced 3 4) elt)
search-string-replaced search-string
last-replacement-replaced last-replacement
next-replacement-replaced last-replacement
last-was-act-and-show nil)
(when (and (= stack-idx stack-len)
......
......@@ -138,6 +138,139 @@ An existing calc stack is reused, otherwise a new one is created."
(nth 1 (calcFunc-cos 1)))
0 4))))))
(ert-deftest calc-test-trig ()
"Trigonometric simplification; bug#33052."
(let ((calc-angle-mode 'rad))
(let ((calc-symbolic-mode t))
(should (equal (math-simplify '(calcFunc-sin (/ (var pi var-pi) 4)))
'(/ (calcFunc-sqrt 2) 2)))
(should (equal (math-simplify '(calcFunc-cos (/ (var pi var-pi) 4)))
'(/ (calcFunc-sqrt 2) 2)))
(should (equal (math-simplify '(calcFunc-sec (/ (var pi var-pi) 4)))
'(calcFunc-sqrt 2)))
(should (equal (math-simplify '(calcFunc-csc (/ (var pi var-pi) 4)))
'(calcFunc-sqrt 2)))
(should (equal (math-simplify '(calcFunc-tan (/ (var pi var-pi) 3)))
'(calcFunc-sqrt 3)))
(should (equal (math-simplify '(calcFunc-cot (/ (var pi var-pi) 3)))
'(/ (calcFunc-sqrt 3) 3))))
(let ((calc-symbolic-mode nil))
(should (equal (math-simplify '(calcFunc-sin (/ (var pi var-pi) 4)))
'(calcFunc-sin (/ (var pi var-pi) 4))))
(should (equal (math-simplify '(calcFunc-cos (/ (var pi var-pi) 4)))
'(calcFunc-cos (/ (var pi var-pi) 4))))
(should (equal (math-simplify '(calcFunc-sec (/ (var pi var-pi) 4)))
'(calcFunc-sec (/ (var pi var-pi) 4))))
(should (equal (math-simplify '(calcFunc-csc (/ (var pi var-pi) 4)))
'(calcFunc-csc (/ (var pi var-pi) 4))))
(should (equal (math-simplify '(calcFunc-tan (/ (var pi var-pi) 3)))
'(calcFunc-tan (/ (var pi var-pi) 3))))
(should (equal (math-simplify '(calcFunc-cot (/ (var pi var-pi) 3)))
'(calcFunc-cot (/ (var pi var-pi) 3)))))))
(ert-deftest calc-test-solve-linear-system ()
"Test linear system solving (bug#35374)."
;; x + y = 3
;; 2x - 3y = -4
;; with the unique solution x=1, y=2
(should (equal
(calcFunc-solve
'(vec
(calcFunc-eq (+ (var x var-x) (var y var-y)) 3)
(calcFunc-eq (- (* 2 (var x var-x)) (* 3 (var y var-y))) -4))
'(vec (var x var-x) (var y var-y)))
'(vec (calcFunc-eq (var x var-x) 1)
(calcFunc-eq (var y var-y) 2))))
;; x + y = 1
;; x + y = 2
;; has no solution
(should (equal
(calcFunc-solve
'(vec
(calcFunc-eq (+ (var x var-x) (var y var-y)) 1)
(calcFunc-eq (+ (var x var-x) (var y var-y)) 2))
'(vec (var x var-x) (var y var-y)))
'(calcFunc-solve
(vec
(calcFunc-eq (+ (var x var-x) (var y var-y)) 1)
(calcFunc-eq (+ (var x var-x) (var y var-y)) 2))
(vec (var x var-x) (var y var-y)))))
;; x - y = 1
;; x + y = 1
;; with the unique solution x=1, y=0
(should (equal
(calcFunc-solve
'(vec
(calcFunc-eq (- (var x var-x) (var y var-y)) 1)
(calcFunc-eq (+ (var x var-x) (var y var-y)) 1))
'(vec (var x var-x) (var y var-y)))
'(vec (calcFunc-eq (var x var-x) 1)
(calcFunc-eq (var y var-y) 0))))
;; 2x - 3y + z = 5
;; x + y - 2z = 0
;; -x + 2y + 3z = -3
;; with the unique solution x=1, y=-1, z=0
(should (equal
(calcFunc-solve
'(vec
(calcFunc-eq
(+ (- (* 2 (var x var-x)) (* 3 (var y var-y))) (var z var-z))
5)
(calcFunc-eq
(- (+ (var x var-x) (var y var-y)) (* 2 (var z var-z)))
0)
(calcFunc-eq
(+ (- (* 2 (var y var-y)) (var x var-x)) (* 3 (var z var-z)))
-3))
'(vec (var x var-x) (var y var-y) (var z var-z)))
;; The `float' forms in the result are just artefacts of Calc's
;; current solver; it should be fixed to produce exact (integral)
;; results in this case.
'(vec (calcFunc-eq (var x var-x) (float 1 0))
(calcFunc-eq (var y var-y) (float -1 0))
(calcFunc-eq (var z var-z) 0))))
;; x = y + 1
;; x = y
;; has no solution
(should (equal
(calcFunc-solve
'(vec
(calcFunc-eq (var x var-x) (+ (var y var-y) 1))
(calcFunc-eq (var x var-x) (var y var-y)))
'(vec (var x var-x) (var y var-y)))
'(calcFunc-solve
(vec
(calcFunc-eq (var x var-x) (+ (var y var-y) 1))
(calcFunc-eq (var x var-x) (var y var-y)))
(vec (var x var-x) (var y var-y)))))
;; x + y + z = 6
;; x + y = 3
;; x - y = 1
;; with the unique solution x=2, y=1, z=3
(should (equal
(calcFunc-solve
'(vec
(calcFunc-eq (+ (+ (var x var-x) (var y var-y)) (var z var-z)) 6)
(calcFunc-eq (+ (var x var-x) (var y var-y)) 3)
(calcFunc-eq (- (var x var-x) (var y var-y)) 1))
'(vec (var x var-x) (var y var-y) (var z var-z)))
'(vec
(calcFunc-eq (var x var-x) 2)
(calcFunc-eq (var y var-y) 1)
(calcFunc-eq (var z var-z) 3))))
;; x = 3
;; x + 4y^2 = 3 (ok, so this one isn't linear)
;; with the unique (double) solution x=3, y=0
(should (equal
(calcFunc-solve
'(vec
(calcFunc-eq (var x var-x) 3)
(calcFunc-eq (+ (var x var-x) (* 4 (^ (var y var-y) 2))) 3))
'(vec (var x var-x) (var y var-y)))
'(vec (calcFunc-eq (var x var-x) 3)
(calcFunc-eq (var y var-y) 0)))))
(provide 'calc-tests)
;;; calc-tests.el ends here
......