Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Big-Float constructors for variable prec constants #1024

Closed
wants to merge 1 commit into from

Conversation

Izaakwltn
Copy link
Collaborator

This addresses issue #1013

I've renamed the existing sb-mpfr compatible Big-Float type to MPFR-Float type, and added a new Big-Float type with two constructors: (BFValue MPFR-Float) and (BFConst (:a -> MPFR-Float)).

This allows for constants to readjust to current precision.

Copy link
Member

@stylewarning stylewarning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a little repetitive. How about something like

(define (mpfr-of bf)
  (match bf
    ((BFValue v) v)
    ((BFConst f) (f))))

With this, something like == would be:

(define (== a b)
  (== (mpfr-of a) (mpfr-of b)))

without all of the case analysis. Unary functions are easier:

(define (lift f x)
  (nest BFValue f mpfr-of x))

so you have

(define (sin x) (lift sin x))

Note that this approach does lead to some nonintuitive behavior. Some values are "privileged" while others are not. So something like

(define pi-1 (* 4 (atan 1))
(define pi-2  pi)

(set precision)

(== pi pi-2) ==> false

happens. I'm not sure if this is ok or not.

@eliaslfox
Copy link
Collaborator

I don't agree with this solution. It adds additional overhead to all bigfloat computations. Pi and E should be made methods so that they alone incur the overhead.

@Izaakwltn
Copy link
Collaborator Author

Izaakwltn commented Oct 18, 2023

Would that be as simple as changing the class definitions from (:a) to (unit -> :a) and making sure it works for each type?

If so I can throw together that alternative.

@stylewarning
Copy link
Member

the only "problem" with this, which may be minor, is that idk any programming language where something that looks like a constant is a function.

(* (* 4/3 (pi)) (^ r 3))

is just non-intuitive, since nobody would imagine pi to be a function or method, and there's no visual indication as such.

FWIW, I don't think big float speed will be dominated by the cost of a few extra pattern matches. With that said, there's definitely a more fundamental problem here.

@Izaakwltn
Copy link
Collaborator Author

Another option:

Have both pi & ee values and c-pi & c-ee compute methods.

This would allow big-floats to use c-pi & c-ee to recompute $\pi$ each time without disturbing the existing syntax. In addition, there may be future types that would benefit from having method constants.

@Izaakwltn Izaakwltn force-pushed the variable-prec-big-float branch 2 times, most recently from f12e0fa to 03ccb89 Compare January 31, 2024 23:46
@Izaakwltn
Copy link
Collaborator Author

I updated Big-Float according to the initial review

@Izaakwltn Izaakwltn force-pushed the variable-prec-big-float branch 3 times, most recently from 785fbd5 to 0f135fd Compare February 1, 2024 05:15
@eliaslfox eliaslfox deleted the variable-prec-big-float branch February 5, 2024 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants