Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8904097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:02:08+00:00 2026-06-15T02:02:08+00:00

I only need i for use in an algorithm. I feel like importing clojure.math

  • 0

I only need i for use in an algorithm. I feel like importing clojure.math is overkill for such a task.

Why?

I have no need for complex results, infact there is no need for a real part with the imaginary part. In my implementation, I only use one value at a time and never combine the two, except for multiplication. The output ends up with no reference to i, the imaginary part is only needed to see the changes in sign in the computation.

Simply put, it would be nice if there was a way to define i as:

(def i (....) ) 

such that (* i i) equals -1.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:02:09+00:00Added an answer on June 15, 2026 at 2:02 am

    If you want (* i i) to evaluate to -1 we’ll need to prepare a macro.

    (ns user)
    (defmacro *
      [& args]
      (let [i-count (count (filter #(= % 'i) args))
            error #(throw (Exception. "Illegal number of imaginary units."))
            i-factor (case (mod i-count 4)
                       0 1
                       2 -1
                       (error))]
        `(clojure.core/* ~@(conj (filter #(not= % 'i) args) i-factor))))
    

    The macro expands to an ordinary multiplication and it shouldn’t interfere with multiplication of real numbers.

    user=> (macroexpand '(* i i))
    (clojure.core/* -1)
    user=> (macroexpand '(* i i 5 i 6 i))
    (clojure.core/* 1 5 6)
    user=> (macroexpand '(* 1.3 3.7))
    (clojure.core/* 1 1.3 3.7)
    user=> (macroexpand '(* i (+ 2 3) i))
    (clojure.core/* -1 (+ 2 3))
    

    Is a macro necessary? Without a macro is present in (* i i) would get evaluated. Since they weren’t defined it would cause a compile-time error. As suggested in the question, we could define i as a value which * knows how to handle. Despite that being possible, it would still be evaluated at runtime. A clear advantage of a macro is the fact that it’s evaluated during compilation and replaced with an ordinary call to clojure.core/* as shown in examples above. Simply put, it’s fast.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a use case where I only need to store certain fields to
Quick version of my question: Is the only time you need to use lock
I need to use unix Style line endings (only LF) in Zend Studio 8/9
Background We need to develop a specialised CMS (internal use only) to support a
I need to get only 1 record from sql result. we use SELECT TOP
I have a class called Property that I only need to display a few
I only need to use the iequals case-insensitive string comparison function from the BOOST
I'd like an efficient algorithm (or library) that I can use in Java to
I have a pkcs12 file. I need to use this to connect to a
I only need to download the first few kilobytes of a file via HTTP.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.