unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Emanuel Berg <incal@dataswamp.org>
To: help-gnu-emacs@gnu.org
Subject: Re: all-substance.el
Date: Thu, 11 Jul 2024 19:59:27 +0200	[thread overview]
Message-ID: <87zfqnizcw.fsf@dataswamp.org> (raw)
In-Reply-To: 87o776ko43.fsf@dataswamp.org

> Here is another interesting program, and very substantial

Added `wash-out', so now we have wash on but also wash of.

See results in particular with half time 6 hours in the below
examples for unexpected things, to most.

Also added docstrings and a bunch of stuff.

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/all-substance.el

(require 'cl-lib)

(defun half-time-to-day-drop (ht)
  (if (< ht 24)
      (/ ht 24 2.0)
    (- 1 (/ 24 ht 2.0)) ))

;; (half-time-to-day-drop 12) ; 0.25
;; (half-time-to-day-drop 48) ; 0.75

(defun all-substance (q d ht &optional verbose day-q)
  "Q is the quantity, for example 10. This is a number; do not use a unit.
D is the number of days, for example 20.
HT is the half-time in hours, for example 6.
Set VERBOSE to return a string.
Set DAY-Q if Q instead is submitted the daily quantity, for example 0.5."
  (cl-loop
    with daily    = (if day-q q (/ q d 1.0))
    with day-drop = (half-time-to-day-drop ht)
    for i downfrom (1- d) to 0
    sum (* daily (expt day-drop i)) into total
    finally return
      (if verbose
          (message "daily %.2f, days %d, total %.2f" daily d total)
        total) ))

;; (all-substance 300 365 6)       ; 0.94
;; (all-substance 0.5  30 6 nil t) ; 0.57
;; (all-substance 365 365 6 t)     ; daily 1.00, days 365, total 1.14

(defun wash-out (q ht &optional days)
  (or days (setq days 5))
  (cl-loop
    with day-drop = (half-time-to-day-drop ht)
    for d from 1 to days
    collect (* q (expt day-drop d)) into res
    finally return res) )

;; (wash-out 1.14 6) ; 0.1      1 day w/o resupply
                    ;; 0.02     2 ..
                    ;; 0.002    3 ..
                    ;; 0.0003   4 ..
                    ;; 0.00003  5 ..

(provide 'all-substance)

-- 
underground experts united
https://dataswamp.org/~incal




      reply	other threads:[~2024-07-11 17:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-10  1:54 all-substance.el Emanuel Berg
2024-07-11 17:59 ` Emanuel Berg [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zfqnizcw.fsf@dataswamp.org \
    --to=incal@dataswamp.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).