sin
result = sin(x)
Input: x · Output: result
What it is
Standard trigonometric functions, computed elementwise. x is the input angle in radians — a scalar, a Vec of any length, or a Mat/Signal of any shape.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = sin(x) | x scalar, Vec, Mat, or Signalnot documented yet | result — | Returns exactly the same type and shape as x, one trig value per element. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
x = 0 to 9
plot(x, sin(x / 2))
· plot: figure 10 (10 points)
from plotting
x = 0 to 9
plot(x, sin(x / 2), "o")
· plot: figure 11 (10 points)
from plotting
n = 0 to 255
x = sin(n * 0.1) + 0.05 * randn(256)
spectrum_mag = x |> fft |> abs
smoothed = spectrum_mag |> dct |> idct
from numerics-dsp
t = (0 to 4095) / 10000
v = 1.2 * sin(2 * pi * 101 * t) + 2.048
c = adc(v, bits = 12, vmin = 0, vmax = 4.096)
print("LSB {c.lsb * 1000:.3f} mV, clipped {c.clipped}, ideal SNR {c.snr_ideal:.1f} dB")
LSB 1.000 mV, clipped 0, ideal SNR 74.0 dB
from noise
How it works
sin/cos/tan/asin/acos/atan/sinh/cosh are complex-aware, on the same route as tanh/exp/log/sqrt (map1_complex): real input still takes the real function (a real value outside a real domain, e.g. asin(2), stays NaN rather than silently promoting to complex -- same convention as sqrt(-1)), and an explicit Value::Complex/ CVec/CMat argument takes the complex branch. See Complex64::{sin,cos,tan,asin,acos,atan,sinh,cosh} in qu-core for the identities. sin/cos/sinh/cosh are entire (no poles anywhere in the plane); tan's poles are exactly the real-axis ones real tan already has (see Complex64::tan's doc comment for the proof); asin/acos have branch points at z = +-1. None of these error at a pole/branch point -- Complex64::div already yields non-finite components there, matching the float semantics the rest of the runtime uses (sqrt(-1) doesn't error either).
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.