trigonometry · MIT License
Overview
Find exact sin, cos, and tan for half angles such as 67.5 degrees or 5pi/8, with nested radicals like sqrt(2+sqrt(2))/2, and double an angle to see the double-angle values.
- Owner-tested on a TI calculator
- Downloaded 13 times
- Version 1.0.0
- 2474 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
- Choice 1 treats the angle you type as half of a known angle: 67.5 degrees is half of 135, 5pi/8 is half of 5pi/4.
- Choice 2 doubles the angle you type and gives the exact values of the double angle.
- In radian mode the number you type is a multiple of pi, so 5/8, 5pi/8, and 0.625pi all mean 5pi/8.
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 find exact values like sin 67.5 and tan 5pi/8 with the half-angle formulas
The idea
Angles such as 67.5 degrees, 22.5 degrees, 15 degrees, or 5pi/8 are not on the unit circle you memorized, but each is half of an angle that is: 67.5 is half of 135, 15 is half of 30, and 5pi/8 is half of 5pi/4. The half-angle formulas turn the known cosine of the bigger angle into the sine, cosine, and tangent of the half angle.
The square root in the formula has a plus or minus sign. You choose it from the quadrant the half angle lands in, not the quadrant of the bigger angle. The results are often nested radicals such as sqrt(2+sqrt(2))/2, or two-term radicals such as (sqrt(6)-sqrt(2))/4.
The formula
sin(u/2) = +-sqrt((1 - cos u)/2)
cos(u/2) = +-sqrt((1 + cos u)/2)
tan(u/2) = (1 - cos u)/sin u = sin u/(1 + cos u)
sin 2u = 2 sin u cos u, cos 2u = cos^2 u - sin^2 u, tan 2u = 2 tan u/(1 - tan^2 u)
u- the known angle; the half angle is u/2
+-- the sign comes from the quadrant of u/2
nested radical- a square root with another square root inside, such as sqrt(2+sqrt(2))
Using the program
- Choose 1 Exact value for a half angle, or 2 Pattern to double an angle. Choice 2 first shows the three double-angle patterns, such as 2sin cos -> sin(2u).
- Choose 1 for degrees or 2 for radians. In radians, type the angle with pi, such as 5pi/8, pi/12, or -pi/8.
- Type the angle. For choice 1 the program shows the angle as a multiple of pi and the angle it is half of, then exact sin, cos, and tan.
- For choice 2 it shows the doubled angle and the exact sin, cos, and tan of the double angle. A tan of 90 degrees shows UNDEFINED.
Worked example
Find the exact values for 67.5 degrees. Choose 1, then 1 for degrees, and type 67.5.
67.5 = 135/2, cos 135 = -sqrt(2)/2, sin 67.5 = sqrt((1 + sqrt(2)/2)/2) = sqrt(2+sqrt(2))/2
The program shows 3pi/8 = half of 3pi/4, then sin 3pi/8 = sqrt(2+sqrt(2))/2, cos 3pi/8 = sqrt(2-sqrt(2))/2, and tan 3pi/8 = 1+sqrt(2).
For 5pi/8, half of 5pi/4, the angle is in Quadrant II, so cosine and tangent are negative: cos 5pi/8 = -sqrt(2-sqrt(2))/2 and tan 5pi/8 = -(1+sqrt(2)).
For pi/12, half of pi/6, the program shows sin pi/12 = (sqrt(6)-sqrt(2))/4 and tan pi/12 = 2-sqrt(3).
Tips and common mistakes
- Pick the sign from where the half angle is: 5pi/8 is in Quadrant II, so its cosine is negative even though 5pi/4 is in Quadrant III.
- The tangent formula (1 - cos u)/sin u has no plus or minus sign, which makes it the easiest of the three.
- sqrt(2+sqrt(2))/2 and (sqrt(6)+sqrt(2))/4 are different kinds of answers: the first is a nested root from the half-angle formula, the second the same kind of value written without nesting, as sum and difference identities give for 15 degrees.
- In radian mode a number without pi is still a multiple of pi, so type 5pi/8, not 1.96.
Where this comes up
Half-angle and double-angle formulas are part of the analytic trigonometry unit of precalculus, and exact values like sin 67.5 or tan pi/12 are a classic test question.
Exact reviewed bytes
Source code
from math import sin,cos,sqrt,pidef cl():print("\n"*11)def pg():input("[enter]");cl()def pk(p,v):while 1:c=input(p).strip()if len(c)==1 and c in v:return int(c)def g(a,b):while b:a,b=b,a%breturn abs(a)def tm(c,k,f):a=abs(c);return ("-" if c<0 else "+" if f else "")+("" if a==1 and k>1 else str(a))+("" if k==1 else "sqrt("+str(k)+")")def tw(v,D):for d in range(1,D+1):for a,b in((1,2),(1,3),(6,2)):for q in range(25):q=(q+1)//2*(1-q%2*2);p=(v*d-q*sqrt(b))/sqrt(a);P=round(p)if abs(p-P)<1e-5*d:h=g(g(P,q),d);P//=h;q//=h;e=d//h;s=(tm(P,a,0) if P else "")+(tm(q,b,P) if q else "")return ("("+s+")" if P and q and e>1 else s)+("/"+str(e) if e>1 else "")def fr(x):p,q,P,Q=0,1,1,0;y=xfor i in range(30):a=int(y//1);p,q,P,Q=P,Q,a*P+p,a*Q+qif abs(x-P/Q)<1e-4/Q/Q:return P,Qif Q>20000 or y==a:returny=1/(y-a)def ex(v):if abs(v)<1e-9:return "0"if v<0:t=ex(-v);return "-"+(t if t[0] in"(s" or "+" not in t and "-" not in t else "("+t+")")r=fr(v)if r:return str(r[0])+("/"+str(r[1]) if r[1]>1 else "")r=fr(v*v)if r:d=r[1];N=r[0]*d;k=1;i=2while i*i<=N:while N%(i*i)==0:N//=i*i;k*=ii+=1h=g(k,d);k//=h;d//=hreturn (str(k) if k>1 else "")+"sqrt("+str(N)+")"+("/"+str(d) if d>1 else "")t=tw(v,12)if t:return tfor e in range(1,9):t=tw(v*v*e*e,1)if t:return "sqrt("+t+")"+("/"+str(e) if e>1 else "")return "%.6g"%vdef an(u):n=round(u*720/pi);h=g(n,720);n//=h;d=720//hreturn ("-" if n<0 else "")+("" if abs(n)==1 else str(abs(n)))+"pi"+("/"+str(d) if d>1 else "") if n else "0"def tn(s,c):return "UNDEFINED" if abs(c)<1e-9 else ex(s/c)def ang():u=pk("1 Deg 2 Rad (5pi/8)\n> ","12")while 1:s=input("Angle? ").replace(" ","").lower()try:if u<2:return float(s)*pi/180a,b=(s.split("/")+["1"])[:2];a=a.replace("pi","");a={"":"1","-":"-1"}.get(a,a);return float(a)*pi/float(b)except Exception:0def show(u,w):print("sin "+w+" = "+ex(sin(u))+"\ncos "+w+" = "+ex(cos(u))+"\ntan "+w+" = "+tn(sin(u),cos(u)))cl();print("5.3 EXACT ANGLES\n(tan 67.5, sin 5pi/8)\n ___(o )>\nDuckieDai (TM)\nhiddenwordscanner.com");pg()while 1:m=pk("1 Exact value (half angle)\n2 Pattern -> double angle\n0 Exit\n> ","012");cl()if m<1:breakif m<2:u=ang();cl();print(an(u)+" = half of "+an(2*u));show(u,an(u));pg()else:print("2sin cos -> sin(2u)\ncos^2-sin^2 -> cos(2u)\n2tan/(1-tan^2) -> tan(2u)");u=ang();cl();print(an(u)+" doubled = "+an(2*u));show(2*u,an(2*u));pg()
- Filename
ANGLE53.py- Size
- 2474 bytes
- SHA-256
f44214f2de9e4e78382aa5c64e3f1c78b37ee09875035641ff8bd8b535429b33
Usage
Inputs
- A menu choice: 1 exact value (half angle), 2 pattern to double angle, 0 exit
- The unit: 1 degrees or 2 radians
- An angle such as 67.5 in degrees, or 5pi/8, pi/12, or -pi/8 in radians
Outputs
- The angle and the angle it is half of (or its double) as multiples of pi
- Exact sin, cos, and tan, such as sqrt(2+sqrt(2))/2 and 1+sqrt(2), or UNDEFINED for tan
Units: Angles in degrees or as a multiple of pi.
Assumptions and limitations
Assumptions
- Choice 1 treats the angle you type as half of a known angle: 67.5 degrees is half of 135, 5pi/8 is half of 5pi/4.
- Choice 2 doubles the angle you type and gives the exact values of the double angle.
- In radian mode the number you type is a multiple of pi, so 5/8, 5pi/8, and 0.625pi all mean 5pi/8.
Constraints
- Exact forms are fractions, square roots of fractions, two-term radicals such as (sqrt(6)-sqrt(2))/4, and nested roots such as sqrt(2+sqrt(2))/2; anything else is shown as a 6-digit decimal.
- The angle is named as a multiple of pi to the nearest pi/720 (a quarter of a degree).
Known failures
- Typing inf or nan as the angle, or an angle too large to hold, stops the program with an error.
- In radian mode, a number without pi is still read as a multiple of pi, so 2.5 means 2.5pi, not 2.5 radians.
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. The published file is the owner's tested source.
- Dependencies
- math
- Suggested calculator name
ANGLE53— 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 ANGLE53 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.