Skip to content

Conversation

yyyyx4
Copy link
Member

@yyyyx4 yyyyx4 commented Feb 14, 2024

When the order of the base element of a finite-field logarithm is already known, factoring the unit-group order can be skipped. PARI's fflog() accepts the order of the base element as an optional input, but that argument is currently not exposed in Sage. This patch takes care of it. An example of the speedup is given in the new doctests.

Copy link
Contributor

@GiacomoPope GiacomoPope left a comment

Choose a reason for hiding this comment

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

Thank you for adding this into Sage. It's been on my TODO list for a while and should have done it myself. This change looks good to me.

Is it worth doing some kind of naive check that the order supplied is the order of both self and the base? Maybe with a check=True arg if nothing else? Just to catch when users accidentally send the wrong order as a param.

        else:
            base_order = _new_GEN_from_mpz_t((<Integer>order).value)
            if check:
                if not (base**base_order).is_one() and (self**base_order).is_one():
                    raise ValueError

@yyyyx4 yyyyx4 force-pushed the public/optionally_pass_order_argument_to_pari_fflog branch from 5821c85 to 26c05b2 Compare February 15, 2024 07:56
@yyyyx4 yyyyx4 force-pushed the public/optionally_pass_order_argument_to_pari_fflog branch from 26c05b2 to 6bd17e5 Compare February 15, 2024 07:58
@yyyyx4
Copy link
Member Author

yyyyx4 commented Feb 15, 2024

Thanks! I added a check= parameter to toggle checking the provided order of the base element. Checking that self lies in the group generated by base should not be disabled by check=False since it's documented that the method will throw an error on such inputs.

Copy link
Contributor

@GiacomoPope GiacomoPope left a comment

Choose a reason for hiding this comment

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

Looks good to me, should check be false by default? If we make it true the function will be a little slower but those who read the documentation can set it to be fast for speedier results?

Copy link

Documentation preview for this PR (built with commit 6bd17e5; changes) is ready! 🎉

vbraun pushed a commit to vbraun/sage that referenced this pull request Feb 18, 2024
sagemathgh-37329: add optional order= argument to .log() method for PARI finite-field elements
    
When the order of the base element of a finite-field logarithm is
already known, factoring the unit-group order can be skipped. PARI's
`fflog()` accepts the order of the base element as an optional input,
but that argument is currently not exposed in Sage. This patch takes
care of it. An example of the speedup is given in the new doctests.
    
URL: sagemath#37329
Reported by: Lorenz Panny
Reviewer(s): Giacomo Pope
vbraun pushed a commit to vbraun/sage that referenced this pull request Feb 19, 2024
sagemathgh-37329: add optional order= argument to .log() method for PARI finite-field elements
    
When the order of the base element of a finite-field logarithm is
already known, factoring the unit-group order can be skipped. PARI's
`fflog()` accepts the order of the base element as an optional input,
but that argument is currently not exposed in Sage. This patch takes
care of it. An example of the speedup is given in the new doctests.
    
URL: sagemath#37329
Reported by: Lorenz Panny
Reviewer(s): Giacomo Pope
@vbraun vbraun merged commit 34de976 into sagemath:develop Feb 25, 2024
@yyyyx4 yyyyx4 deleted the public/optionally_pass_order_argument_to_pari_fflog branch February 25, 2024 12:03
AZ-0 added a commit to AZ-0/sage that referenced this pull request Jul 13, 2024
vbraun pushed a commit to vbraun/sage that referenced this pull request Jul 20, 2024
sagemathgh-38359: Homogenise `.log()` api across implementations of finite field elements
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

Fixes sagemath#38350 by adding `order=` and `check=` arguments to the `.log()`
method of finite field elements, under all implementations.
- `element_pari_ffelt.pyx`: done by @yyyyx4 in sagemath#37329.
- `element_ntl_gf2e.pyx`: if provided, does not compute `base_order`.
- `element_givaro.pyx`: if provided, passes `order` to the underlying
`discrete_log` call.
- `integer_mod.pyx`: the argument is discarded (unless `check=True`, in
which case the order is checked).

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#38359
Reported by: Justin Carel
Reviewer(s): Lorenz Panny
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants