Deprecated: Creation of dynamic property wpdb::$categories is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/wp-db.php on line 668

Deprecated: Creation of dynamic property wpdb::$post2cat is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/wp-db.php on line 668

Deprecated: Creation of dynamic property wpdb::$link2cat is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/wp-db.php on line 668

Deprecated: Return type of WP_Theme::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-theme.php on line 554

Deprecated: Return type of WP_Theme::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-theme.php on line 595

Deprecated: Return type of WP_Theme::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-theme.php on line 535

Deprecated: Return type of WP_Theme::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-theme.php on line 544

Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /usr/home/bugyo/public_html/b-log/wp-includes/comment-template.php on line 1739

Deprecated: Return type of WP_REST_Request::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/rest-api/class-wp-rest-request.php on line 960

Deprecated: Return type of WP_REST_Request::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/rest-api/class-wp-rest-request.php on line 980

Deprecated: Return type of WP_REST_Request::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/rest-api/class-wp-rest-request.php on line 992

Deprecated: Return type of WP_REST_Request::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/rest-api/class-wp-rest-request.php on line 1003

Deprecated: Return type of WP_Block_List::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-block-list.php on line 151

Deprecated: Return type of WP_Block_List::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-block-list.php on line 175

Deprecated: Return type of WP_Block_List::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-block-list.php on line 164

Deprecated: Return type of WP_Block_List::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-block-list.php on line 186

Deprecated: Return type of WP_Block_List::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-block-list.php on line 138

Deprecated: Return type of WP_Block_List::offsetExists($index) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-block-list.php on line 75

Deprecated: Return type of WP_Block_List::offsetGet($index) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-block-list.php on line 89

Deprecated: Return type of WP_Block_List::offsetSet($index, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-block-list.php on line 110

Deprecated: Return type of WP_Block_List::offsetUnset($index) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-block-list.php on line 127

Deprecated: Return type of WP_Block_List::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-block-list.php on line 199

Deprecated: Calling get_class() without arguments is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/class-http.php on line 328

Deprecated: Return type of Requests_Cookie_Jar::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/Requests/Cookie/Jar.php on line 63

Deprecated: Return type of Requests_Cookie_Jar::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/Requests/Cookie/Jar.php on line 73

Deprecated: Return type of Requests_Cookie_Jar::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/Requests/Cookie/Jar.php on line 89

Deprecated: Return type of Requests_Cookie_Jar::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/Requests/Cookie/Jar.php on line 102

Deprecated: Return type of Requests_Cookie_Jar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/Requests/Cookie/Jar.php on line 111

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 40

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 51

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 68

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 82

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/home/bugyo/public_html/b-log/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 91

Deprecated: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/wp-db.php on line 3030

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-term.php on line 198

Deprecated: Creation of dynamic property WP_Term::$object_id is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-term.php on line 198

Warning: Cannot modify header information - headers already sent by (output started at /usr/home/bugyo/public_html/b-log/wp-includes/class-wp-block-list.php:14) in /usr/home/bugyo/public_html/b-log/wp-includes/feed-rss2.php on line 8
記号処理 – B-LOG https://blog.bugyo.tk/b-log bugyoのlog。決してblogではない。 Mon, 14 Nov 2011 18:02:58 +0000 en-US hourly 1 https://wordpress.org/?v=5.7.2 [数式処理][Scheme] 算術式を簡単にする https://blog.bugyo.tk/b-log/archives/775 https://blog.bugyo.tk/b-log/archives/775#respond Sun, 06 Nov 2011 04:13:56 +0000
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/category.php on line 383
http://blog.bugyo.tk/b-log/?p=775 Continue reading [数式処理][Scheme] 算術式を簡単にする]]> 微分などで複雑になった算術式を簡素化するには次のようにする。

(define (simple exp)
  (define (flat lst op)
    (append-map! (lambda (x)
                   (if (and (pair? x) (eq? (car x) op))
                       (flat (cdr x) op)
                       (list x)))
                 lst))
  
  (define (constant-fold args init op)
    (define (cf args num acc)
      (cond ((null? args)
             (values acc num))
            ((number? (car args))
             (cf (cdr args) (op num (car args)) acc))
            (else
             (cf (cdr args) num (append! acc (list (car args)))))))
    (cf args init '() ))
  
  (define (simple-+ args)
    (set! args (map simple args))
    (set! args (flat args '+))
    (receive (exps num) (constant-fold args 0 +)
     (cond ((null? exps) num)
           (else `(+ ,@args num)))))
  
  (define (simple-* args)
    (call/cc
     (lambda (c)
       (set! args (map simple args))
       (set! args (flat args '*))
       (map (lambda (x)
              (when (and (number? x) (= x 0))
                    (c 0)))
            args)
       (set! args (constant-fold args 1 *))
       (set! args (remove (lambda (x)
                            (and (number? x)(= x 1)))
                          args))
       (if (= 1 (length args))
           (car args)
           `(* ,@args)))))

  (define (simple-expt base ex)
    (set! base (simple base))
    (set! ex (simple ex))
    (cond ((or (and (number? base) (= base 1))
               (and (number? ex) (= ex 0)))
           1)
          ((or (and (number? base) (= base 0))
               (and (number? ex) (= ex 1)))
           base)
          (else
           `(expt ,base ,ex))))

  (define (simple-- arg)
    (cond ((number? arg) (- arg))
          ((and (pair? arg)
                (eq? (car arg) '+))
           (simple-+ (map (lambda (x) (list '- x))
                          (cdr arg))))
          ((and (pair? arg)
                (eq? (car arg) '*))
           (simple-* (map (lambda (x) (list '- x))
                          (cdr arg))))
          (else
           `(- ,arg))))
  
  (cond ((not (pair? exp)) exp)
        ((eq? (car exp) '-)
         (simple-- (cadr exp)))
        ((eq? (car exp) '+)
         (simple-+ (cdr exp)))
        ((eq? (car exp) '*)
         (simple-* (cdr exp)))
        ((eq? (car exp) 'expt)
         (simple-expt (cadr exp) (caddr exp)))
        (else
         `(,(car exp) ,@(map simple (cdr exp))))))
> (simple (deriv '(expt (* (sin x) (cos x)) 1/2) 'x))
=> (* (expt (* (sin x) (cos x)) -1/2) (+ (* (cos x) (cos x)) (* (sin x) (- (sin x)))) 1/2)

`-‘ 演算子は単項演算子としてのみ使える。

]]>
https://blog.bugyo.tk/b-log/archives/775/feed 0
[数式処理][Scheme] 微分する https://blog.bugyo.tk/b-log/archives/772 https://blog.bugyo.tk/b-log/archives/772#respond Sun, 06 Nov 2011 04:09:32 +0000
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/category.php on line 378

Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/category.php on line 379

Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/category.php on line 380

Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/category.php on line 381

Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/category.php on line 382

Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /usr/home/bugyo/public_html/b-log/wp-includes/category.php on line 383
http://blog.bugyo.tk/b-log/?p=772 Continue reading [数式処理][Scheme] 微分する]]> 複雑な微分をするときは計算機に任せた方が良いように思う。

Scheme で微分するには次のようにする。

(define (deriv exp var)
  (cond ((eq? exp var) 1)
	((not (pair? exp)) 0)
	((eq? (car exp) '-)
	 `(- ,(deriv (cadr exp) var)))
	((eq? (car exp) '+)
	 `(+ ,(deriv (cadr exp) var) ,(deriv (caddr exp) var)))
	((eq? (car exp) '*)
	 `(+ (* ,(deriv (cadr exp) var)
		,(caddr exp))
	     (* ,(cadr exp)
		,(deriv (caddr exp) var))))
	((eq? (car exp) 'expt)
	 (let ((g (cadr exp))
	       (n (caddr exp)))
	   `(* (* ,n (expt ,g ,(- n 1))) ,(deriv g var))))
	((eq? (car exp) 'sin)
	 `(* (cos ,(cadr exp)) ,(deriv (cadr exp) var)))
	((eq? (car exp) 'cos)
	 `(* (- (sin ,(cadr exp))) ,(deriv (cadr exp) var)))
        ((eq? (car exp) 'tan)
         `(* (+ 1 (expt ,exp 2)) ,(deriv (cadr exp) var)))
	(else (error "not yet."))))
> (deriv '(expt (* (sin x) (cos x)) 1/2)) 'x)
=> (* (* 1/2
         (expt (* (sin x) (cos x)) -1/2))
      (+ (* (* (cos x) 1)
	    (cos x))
         (* (sin x)
	    (* (- (sin x)) 1))))

`-‘ 演算子は単項演算子としてのみ使える。

]]>
https://blog.bugyo.tk/b-log/archives/772/feed 0