exponential functions · MIT License
Overview
Expand a log of a product, quotient, power, or root into simpler logs, or condense a sum of logs back into a single log, in log, a chosen base, or ln.
- Owner-tested on a TI calculator
- Version 1.0.0
- 2851 bytes
- Uses math
Tried it? Did this program work on your calculator?
Before you run it
- TI-84 Plus CE Python · No calculator OS or Python App version has been verified.
- TI Connect CE .py transfer to the Python App; the owner's transfer details were not recorded
- Every variable is assumed to be positive, so each log is defined.
- Products are written with *, and sqrt( ) counts as a power of 1/2.
- A sum or difference inside the log, such as x+1, is kept whole, because the log of a sum cannot be split.
Try the DuckieDai calculator screen
Follow the program's prompts and result flow before downloading.
TI-84 Plus CE Python · screen preview
Learn the math
How to expand and condense logarithms
The idea
A logarithm turns multiplication into addition. Because of that, the log of a product, quotient, or power can be split into a sum of simpler logs, called expanding, and a sum of logs with numbers in front can be packed back into one log, called condensing.
Expanding helps when you need to differentiate or simplify; condensing helps when you solve an equation, because one log on each side can be undone. The same three rules work for log, ln, and a log in any base.
The formula
log(xy) = log(x) + log(y)
log(x/y) = log(x) - log(y)
log(x^n) = n log(x)
product rule- the log of a product is the sum of the logs
quotient rule- the log of a quotient is the log of the top minus the log of the bottom
power rule- a power inside a log moves to the front as a number; a square root is the power 1/2
Using the program
- Choose 1 to expand or 2 to condense, then 1 for log, 2 for a base you choose, or 3 for ln.
- To expand, type what is inside the log with * for multiplication, such as (x^3*y^2)/z^4. sqrt( ) counts as a power of 1/2.
- To condense, type how many terms there are, then for each term its number in front, such as 2 or -1, and what is inside its log.
- A number that is an exact power of the base, such as 8 in base 2, becomes a whole number in the answer.
Worked example
Expand log((x^3*y^2)/z^4). Choose 1, then 1 for log, and type (x^3*y^2)/z^4.
log(x^3) + log(y^2) - log(z^4) = 3log(x) + 2log(y) - 4log(z)
The program shows RESULT: 3log(x) + 2log(y) - 4log(z).
Expand log_2(8x/sqrt(y)). Choose 1, then 2, base 2, and type 8*x/sqrt(y). log_2(8) is 3, so the program shows 3 + log_2(x) - (1/2)log_2(y).
Condense 2ln(x) + 3ln(y) - ln(z). Choose 2, then 3 for ln, type 3 terms, then 2 and x, 3 and y, and -1 and z. The program shows ln((x^2*y^3)/z).
Tips and common mistakes
- There is no rule for the log of a sum: log(x+1) cannot be split, so the program keeps it whole.
- Every variable is assumed to be positive, so each log in the answer is defined.
- Write products with *: 2x is read as a single factor, while 2*x is split into log(2) + log(x).
- When condensing, a negative number in front sends that factor to the bottom of the fraction.
Where this comes up
The properties of logarithms are a core part of the logarithmic functions unit of algebra 2, precalculus, and college algebra, and calculus uses them for logarithmic differentiation.
Exact reviewed bytes
Source code
from math import logdef P(s):print(s);input("[enter]");print("\n"*11)def fmt(v):if abs(v-round(v))<1e-9:return str(int(round(v)))for d in range(2,101):n=round(v*d)if abs(v-n/d)<1e-8:return str(n)+"/"+str(d)return str(round(v,6))def st(s):while s[:1]=="(" and s[-1:]==")":d=0for i in range(len(s)):d+=(s[i]=="(")-(s[i]==")")if d<1 and i<len(s)-1:return ss=s[1:-1]return sdef sp(s,o):r=[];l=0;d=0for i in range(len(s)):c=s[i];d+=(c=="(")-(c==")")if d==0 and c in o and i>l:r+=[s[l:i],c];l=i+1return r+[s[l:]]def val(s):s=st(s)if "/" in s:a,b=s.split("/");v=float(a)/float(b)else:v=float(s)if v-v:raise ValueError("Not a number")return vdef bi(s):d=0for i in range(len(s)):c=s[i];d+=(c=="(")-(c==")")if d==0 and i and c in"+-" and s[i-1] not in"^*/(" and not(i>1 and s[i-1] in"eE" and s[i-2] in"0123456789."):return 1return 0def at(s,c=1):s=st(s)if bi(s):return [(s,c)]p=sp(s,"*/")if len(p)>1:r=[];g=1for q in p:if q=="*":g=1elif q=="/":g=-1else:r+=at(q,c*g)return rp=sp(s,"^")if len(p)==3:return at(p[0],c*val(p[2]))if s[:5]=="sqrt(" and s[-1:]==")":return at(s[5:-1],c/2)if not s:raise ValueError("Missing factor")return [(s,c)]def ex(s,L,b):k=0;T={};O=[]for t,c in at(s.replace(" ","")):try:n=val(t)if b:e=round(log(n)/log(b))if abs(b**e-n)<1e-8*max(1,n):k+=c*e;continueexcept Exception:passif t not in T:O.append(t);T[t]=0T[t]+=co=fmt(k) if abs(k)>1e-10 else ""for t in O:c=T[t]if abs(c)<1e-9:continuef=fmt(abs(c));v=("" if f=="1" else "("+f+")" if "/" in f else f)+L+"("+t+")"o+=((" - " if c<0 else " + ")+v) if o else ("-" if c<0 else "")+vreturn o or "0"def cn(L):n=int(input("# of terms? "));t=[];u=[]for i in range(n):c=val(input("Term "+str(i+1)+" coef? "));a=input(" Inside? ").strip()if not a or c==0:continuep=a if not any(h in a for h in "+-*/^") else "("+a+")"f=fmt(abs(c))if abs(c)!=1:p+="^"+("("+f+")" if "/" in f else f)(t if c>0 else u).append(p)s="*".join(t) or "1"if u:s=(s if len(t)<2 else "("+s+")")+"/"+(u[0] if len(u)<2 else "("+"*".join(u)+")")return L+"("+s+")"def ch():while 1:c=input("1 log 2 log_b 3 ln? ").strip()if c=="1":return "log",10if c=="3":return "ln",Noneif c=="2":try:b=val(input("Base? "))if b>0 and b!=1:f=fmt(b);return "log_"+("("+f+")" if "/" in f else f),bexcept Exception:passprint("Base >0, not 1")P("DuckieDai TM\nLOG PROPERTIES\n __(o )> quack!\nhiddenwordscanner.com")while 1:c=input("1 Expand 2 Condense\n3 Quit? ").strip()if c=="3":breakif c not in("1","2"):continueL,b=ch()try:if c=="1":print("Use * : (x^3*y^2)/z^4");a=ex(input("Inside log? "),L,b)else:a=cn(L)print("\n"*11);P("RESULT:\n"+a)except Exception as e:P("INPUT ERROR:\n"+str(e))
- Filename
LOGPROPU.py- Size
- 2851 bytes
- SHA-256
7e06684afae5a8f5adeafffa3cd173dbdcc61bb92b6715b16c642542995a145d
Usage
Inputs
- 1 to expand or 2 to condense
- The log: 1 log, 2 log with a base you choose, or 3 ln
- To expand, what is inside the log, written with * and / such as (x^3*y^2)/z^4
- To condense, how many terms, then each term's number in front and what is inside
Outputs
- The expanded expression, such as 3log(x) + 2log(y) - 4log(z)
- The condensed single log, such as log(x^3/y^2)
- Whole numbers in place of logs of exact powers of the base, such as 3 for log_2(8)
Units: Pure expressions; no units.
Assumptions and limitations
Assumptions
- Every variable is assumed to be positive, so each log is defined.
- Products are written with *, and sqrt( ) counts as a power of 1/2.
Constraints
- A sum or difference inside the log, such as x+1, is kept whole, because the log of a sum cannot be split.
- Numbers may be decimals or fractions such as 1/2; a base must be greater than 0 and not 1.
Known failures
- Two factors written side by side without *, such as 2x, are treated as one factor.
- Typing something other than a whole number for the number of terms shows INPUT ERROR with Python's own message.
Compatibility and review
- Review status
- Owner-tested on a TI calculator
- Tested on
- Owner reports personally running this program on a TI-84 Plus CE Python calculator; the test date, OS version, and Python App version were not recorded
- What happened
- Owner reported pass on the calculator before two fixes: a sum or difference inside the log, such as x+1*y, is now kept whole instead of being split at the *, which gave a wrong answer, and inf or nan typed as a number now shows INPUT ERROR: Not a number. Every other step is unchanged; this exact file has not yet been rerun on a calculator.
- Dependencies
- math
- Suggested calculator name
LOGPROPU— you can give it another valid, unique name when you transfer it- Desktop test cases
- Not available for this interactive-only source
This exact source auto-launches an interactive calculator session, so compatibility evidence comes from the recorded physical-device review rather than an importable desktop fixture.
Transfer and launch
Download the .py file, send it to your calculator with TI Connect CE as LOGPROPU or another name, then open the Python App and try the worked example on this page first. This release has no verified calculator OS or Python App version; treat transfer and execution as unverified until independently tested.
Full installation and troubleshooting guide. Check your teacher's or exam's rules before using any program.
Version history
- 1.0.0 — current version, published . Download this reviewed version
Related learning
Did a DuckieDai program help with your homework? Every program here is free. If you would like to say thanks, you can leave a tip on Cash App ($duckiedai214) or read what tips pay for.
Independent compatibility resource: Hidden Word Scanner is independent and is not affiliated with or endorsed by Texas Instruments. TI product names describe compatibility only.
Action-count privacy: Successful downloads, preview starts, and preview completions increment same-origin aggregate counters, and so does a Yes or No answer about whether the program worked. Your browser notes that you answered; that note is never sent to the site. No entered values, source text, IP address, account, cookie, device identifier, or fingerprint is stored with these counts.