Macfarlane was born in Blairgowrie, Scotland and studied at the University of Edinburgh. His doctoral thesis "The disruptive discharge of electricity" reported on experimental results from the laboratory of Peter Guthrie Tait.
In 1878 Macfarlane spoke at the Royal Society of Edinburgh on algebraic logic as introduced by George Boole. He was elected a Fellow of the Royal Society of Edinburgh. His proposers were Peter Guthrie Tait, Philip Kelland, Alexander Crum Brown, and John Hutton Balfour. The next year he published Principles of the Algebra of Logic which interpreted Boolean variable expressions with algebraic manipulation.
During his life, Macfarlane played a prominent role in research and education. He taught at the universities of Edinburgh and St Andrews, was physics professor at the University of Texas (1885–1894), professor of Advanced Electricity, and later of mathematical physics, at Lehigh University. In 1896 Macfarlane encouraged the association of quaternion students to promote the algebra. He became the Secretary of the Quaternion Society, and in 1909 its president. He edited the Bibliography of Quaternions that the Society published in 1904.
Macfarlane was also the author of a popular 1916 collection of mathematical biographies (Ten British Mathematicians), a similar work on physicists (Lectures on Ten British Physicists of the Nineteenth Century, 1919). Macfarlane was caught up in the revolution in geometry during his lifetime, in particular through the influence of G. B. Halsted who was mathematics professor at the University of Texas. Macfarlane originated an Algebra of Physics, which was his adaptation of quaternions to physical science. His first publication on Space Analysis preceded the presentation of Minkowski Space by seventeen years.
Macfarlane actively participated in several International Congresses of Mathematicians including the primordial meeting in Chicago, 1893, and the Paris meeting of 1900 where he spoke on "Application of space analysis to curvilinear coordinates".
Alexander Macfarlane stylized his work as "Space Analysis". In 1894 he published his five earlier papers and a book review of Alexander McAulay's Utility of Quaternions in Physics. Page numbers are carried from previous publications, and the reader is presumed familiar with quaternions. The first paper is "Principles of the Algebra of Physics" where he first proposes the hyperbolic quaternion algebra, since "a student of physics finds a difficulty in principle of quaternions which makes the square of a vector negative." The second paper is "The Imaginary of the Algebra". Similar to Homersham Cox (1882/83), Macfarlane uses the hyperbolic versor as the hyperbolic quaternion corresponding to the versor of Hamilton. The presentation is encumbered by the notation
Papers three and four are "Fundamental Theorems of Analysis Generalized for Space" and "On the definition of the Trigonometric Functions", which he had presented the previous year in Chicago at the Congress of Mathematicians held in connection with the World's Columbian Exhibition. He follows George Salmon in exhibiting the hyperbolic angle, argument of hyperbolic functions. The fifth paper is "Elliptic and Hyperbolic Analysis" which considers the spherical law of cosines as the fundamental theorem of the sphere, and proceeds to analogues for the ellipsoid of revolution, general ellipsoid, and equilateral hyperboloids of one and two sheets, where he provides the hyperbolic law of cosines.
In 1900 Alexander published "Hyperbolic Quaternions" with the Royal Society in Edinburgh, and included a sheet of nine figures, two of which display conjugate hyperbolas. Having been stung in the Great Vector Debate over the non-associativity of his Algebra of Physics, he restored associativity by reverting to biquaternions, an algebra used by students of Hamilton since 1853.