ramarren / unit-formula Goto Github PK
View Code? Open in Web Editor NEWCommon Lisp library for unit conversions and unit verified formulas
Common Lisp library for unit conversions and unit verified formulas
Thanks for this library, it's been amazing to work with. I was wondering if you have given thought to allowing formulas as operators within a formula?
A trival example would be:
(defformula* area ((length meters) (width meters))
(* length width))
(defformula* volume ((length meters) (width meters) (height meters))
(* (area length width) height))
;;; a trival and inaccurate version of the 4th dimension
(defformula* space-time ((length meters) (width meters) (height meters) (time seconds))
(* (volume length width height) time))
In writing some code I came to the point of trying to build formulas based upon other formulas. To do so I was rewriting a lot of code for each higher level formula like this:
(defformula* area ((length meters) (width meters))
(* length width))
(defformula* volume ((length meters) (width meters) (height meters))
(* length width height))
(defformula* space-time ((length meters)(width meters)(height meters)(time seconds))
(* length width height time))
Not so bad, but increasing complexity begs for code reuse. Another option seems to be writing a lot of small formulas called by a parent function like this:
(defformula* area ((length meters) (width meters))
(* length width))
(defformula* %volume% ((area m^2)(height meters))
(* area height))
(defun volume (length width height)
(%volume% (area length width) height))
(defformula* %space-time% ((volume m^3) (time seconds))
(* volume time))
(defun space-time (length width height time)
(%space-time% (volume length width height) time))
This allows for code reuse, which is great, but enlarges the amount of "boilerplate". By allowing for formulas to call other formulas I think it would give the most code reuse as well as remove the need for extra code. How have you dealt with the subject of complex formulas that build upon each other in your practical coding?
Thanks again for reviving this library, modernizing it, and sharing.
Cheers,
-Elliott
Hello,
I (or, more precisely, a student of mine) wanted to add units as follows:
(define-units volume-a (1 ml))
(define-units volume-b (2 ml))
(define-units total-volume (+ volume-a volume-b))
... which does not work ("cannot add units of different dimensions"). However, as much as I see, the dimensions should fit?
Thank you,
Nicolas
Hi,
I believe that many of the length conversions can be more accurately expressed as ratios rather than floats. For example, centimeters is expressed as 0.01. This results in the following...
(convert-unit '(100.00 cm) 'm) => 0.9999999776482582d0
It looks like it was done this way in the original novak library. Do you think this is for efficiency's sake?
Regards,
Andy
Hello,
I would be interested how I could use unit-formula in the following situation:
I have a set of physical parameters with units and would like to calculate from those dimensionless parameters for inserting them in a numerical calculation.
Should I declare those parameters all with define-units and then define formulae involving those parameters?
Thanks, Nicolas
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.