(sin (* PI (* z1 (- z0))))

Percentage Accurate: 52.1% → 96.1%
Time: 1.7s
Alternatives: 3
Speedup: 1.0×

Specification

?
\[\sin \left(\pi \cdot \left(z1 \cdot \left(-z0\right)\right)\right) \]
(FPCore (z1 z0)
  :precision binary64
  (sin (* PI (* z1 (- z0)))))
double code(double z1, double z0) {
	return sin((((double) M_PI) * (z1 * -z0)));
}
public static double code(double z1, double z0) {
	return Math.sin((Math.PI * (z1 * -z0)));
}
def code(z1, z0):
	return math.sin((math.pi * (z1 * -z0)))
function code(z1, z0)
	return sin(Float64(pi * Float64(z1 * Float64(-z0))))
end
function tmp = code(z1, z0)
	tmp = sin((pi * (z1 * -z0)));
end
code[z1_, z0_] := N[Sin[N[(Pi * N[(z1 * (-z0)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sin \left(\pi \cdot \left(z1 \cdot \left(-z0\right)\right)\right)

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 3 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 52.1% accurate, 1.0× speedup?

\[\sin \left(\pi \cdot \left(z1 \cdot \left(-z0\right)\right)\right) \]
(FPCore (z1 z0)
  :precision binary64
  (sin (* PI (* z1 (- z0)))))
double code(double z1, double z0) {
	return sin((((double) M_PI) * (z1 * -z0)));
}
public static double code(double z1, double z0) {
	return Math.sin((Math.PI * (z1 * -z0)));
}
def code(z1, z0):
	return math.sin((math.pi * (z1 * -z0)))
function code(z1, z0)
	return sin(Float64(pi * Float64(z1 * Float64(-z0))))
end
function tmp = code(z1, z0)
	tmp = sin((pi * (z1 * -z0)));
end
code[z1_, z0_] := N[Sin[N[(Pi * N[(z1 * (-z0)), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sin \left(\pi \cdot \left(z1 \cdot \left(-z0\right)\right)\right)

Alternative 1: 96.1% accurate, 0.3× speedup?

\[\mathsf{copysign}\left(1, z1\right) \cdot \left(\mathsf{copysign}\left(1, z0\right) \cdot \begin{array}{l} \mathbf{if}\;\pi \cdot \left(\left|z1\right| \cdot \left(-\left|z0\right|\right)\right) \leq -2 \cdot 10^{+32}:\\ \;\;\;\;\sin \left(\left(-1.5707963267948966\right) - -0.5 \cdot \pi\right)\\ \mathbf{else}:\\ \;\;\;\;\sin \left(-3.141592653589793 \cdot \left(\left|z0\right| \cdot \left|z1\right|\right)\right)\\ \end{array}\right) \]
(FPCore (z1 z0)
  :precision binary64
  (*
 (copysign 1.0 z1)
 (*
  (copysign 1.0 z0)
  (if (<= (* PI (* (fabs z1) (- (fabs z0)))) -2e+32)
    (sin (- (- 1.5707963267948966) (* -0.5 PI)))
    (sin (* -3.141592653589793 (* (fabs z0) (fabs z1))))))))
double code(double z1, double z0) {
	double tmp;
	if ((((double) M_PI) * (fabs(z1) * -fabs(z0))) <= -2e+32) {
		tmp = sin((-1.5707963267948966 - (-0.5 * ((double) M_PI))));
	} else {
		tmp = sin((-3.141592653589793 * (fabs(z0) * fabs(z1))));
	}
	return copysign(1.0, z1) * (copysign(1.0, z0) * tmp);
}
public static double code(double z1, double z0) {
	double tmp;
	if ((Math.PI * (Math.abs(z1) * -Math.abs(z0))) <= -2e+32) {
		tmp = Math.sin((-1.5707963267948966 - (-0.5 * Math.PI)));
	} else {
		tmp = Math.sin((-3.141592653589793 * (Math.abs(z0) * Math.abs(z1))));
	}
	return Math.copySign(1.0, z1) * (Math.copySign(1.0, z0) * tmp);
}
def code(z1, z0):
	tmp = 0
	if (math.pi * (math.fabs(z1) * -math.fabs(z0))) <= -2e+32:
		tmp = math.sin((-1.5707963267948966 - (-0.5 * math.pi)))
	else:
		tmp = math.sin((-3.141592653589793 * (math.fabs(z0) * math.fabs(z1))))
	return math.copysign(1.0, z1) * (math.copysign(1.0, z0) * tmp)
function code(z1, z0)
	tmp = 0.0
	if (Float64(pi * Float64(abs(z1) * Float64(-abs(z0)))) <= -2e+32)
		tmp = sin(Float64(Float64(-1.5707963267948966) - Float64(-0.5 * pi)));
	else
		tmp = sin(Float64(-3.141592653589793 * Float64(abs(z0) * abs(z1))));
	end
	return Float64(copysign(1.0, z1) * Float64(copysign(1.0, z0) * tmp))
end
function tmp_2 = code(z1, z0)
	tmp = 0.0;
	if ((pi * (abs(z1) * -abs(z0))) <= -2e+32)
		tmp = sin((-1.5707963267948966 - (-0.5 * pi)));
	else
		tmp = sin((-3.141592653589793 * (abs(z0) * abs(z1))));
	end
	tmp_2 = (sign(z1) * abs(1.0)) * ((sign(z0) * abs(1.0)) * tmp);
end
code[z1_, z0_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(Pi * N[(N[Abs[z1], $MachinePrecision] * (-N[Abs[z0], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], -2e+32], N[Sin[N[((-1.5707963267948966) - N[(-0.5 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sin[N[(-3.141592653589793 * N[(N[Abs[z0], $MachinePrecision] * N[Abs[z1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\mathsf{copysign}\left(1, z1\right) \cdot \left(\mathsf{copysign}\left(1, z0\right) \cdot \begin{array}{l}
\mathbf{if}\;\pi \cdot \left(\left|z1\right| \cdot \left(-\left|z0\right|\right)\right) \leq -2 \cdot 10^{+32}:\\
\;\;\;\;\sin \left(\left(-1.5707963267948966\right) - -0.5 \cdot \pi\right)\\

\mathbf{else}:\\
\;\;\;\;\sin \left(-3.141592653589793 \cdot \left(\left|z0\right| \cdot \left|z1\right|\right)\right)\\


\end{array}\right)
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (PI.f64) (*.f64 z1 (neg.f64 z0))) < -2.0000000000000001e32

    1. Initial program 52.1%

      \[\sin \left(\pi \cdot \left(z1 \cdot \left(-z0\right)\right)\right) \]
    2. Step-by-step derivation
      1. lift-sin.f64N/A

        \[\leadsto \color{blue}{\sin \left(\pi \cdot \left(z1 \cdot \left(-z0\right)\right)\right)} \]
      2. lift-*.f64N/A

        \[\leadsto \sin \color{blue}{\left(\pi \cdot \left(z1 \cdot \left(-z0\right)\right)\right)} \]
      3. lift-*.f64N/A

        \[\leadsto \sin \left(\pi \cdot \color{blue}{\left(z1 \cdot \left(-z0\right)\right)}\right) \]
      4. associate-*r*N/A

        \[\leadsto \sin \color{blue}{\left(\left(\pi \cdot z1\right) \cdot \left(-z0\right)\right)} \]
      5. lift-neg.f64N/A

        \[\leadsto \sin \left(\left(\pi \cdot z1\right) \cdot \color{blue}{\left(\mathsf{neg}\left(z0\right)\right)}\right) \]
      6. distribute-rgt-neg-outN/A

        \[\leadsto \sin \color{blue}{\left(\mathsf{neg}\left(\left(\pi \cdot z1\right) \cdot z0\right)\right)} \]
      7. sin-negN/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(\sin \left(\left(\pi \cdot z1\right) \cdot z0\right)\right)} \]
      8. cos-+PI/2-revN/A

        \[\leadsto \color{blue}{\cos \left(\left(\pi \cdot z1\right) \cdot z0 + \frac{\mathsf{PI}\left(\right)}{2}\right)} \]
      9. lower-cos.f64N/A

        \[\leadsto \color{blue}{\cos \left(\left(\pi \cdot z1\right) \cdot z0 + \frac{\mathsf{PI}\left(\right)}{2}\right)} \]
      10. lower-+.f64N/A

        \[\leadsto \cos \color{blue}{\left(\left(\pi \cdot z1\right) \cdot z0 + \frac{\mathsf{PI}\left(\right)}{2}\right)} \]
      11. lower-*.f64N/A

        \[\leadsto \cos \left(\color{blue}{\left(\pi \cdot z1\right) \cdot z0} + \frac{\mathsf{PI}\left(\right)}{2}\right) \]
      12. *-commutativeN/A

        \[\leadsto \cos \left(\color{blue}{\left(z1 \cdot \pi\right)} \cdot z0 + \frac{\mathsf{PI}\left(\right)}{2}\right) \]
      13. lower-*.f64N/A

        \[\leadsto \cos \left(\color{blue}{\left(z1 \cdot \pi\right)} \cdot z0 + \frac{\mathsf{PI}\left(\right)}{2}\right) \]
      14. lift-PI.f64N/A

        \[\leadsto \cos \left(\left(z1 \cdot \pi\right) \cdot z0 + \frac{\color{blue}{\pi}}{2}\right) \]
      15. metadata-evalN/A

        \[\leadsto \cos \left(\left(z1 \cdot \pi\right) \cdot z0 + \frac{\pi}{\color{blue}{1 + 1}}\right) \]
      16. lower-/.f64N/A

        \[\leadsto \cos \left(\left(z1 \cdot \pi\right) \cdot z0 + \color{blue}{\frac{\pi}{1 + 1}}\right) \]
      17. metadata-eval6.1%

        \[\leadsto \cos \left(\left(z1 \cdot \pi\right) \cdot z0 + \frac{\pi}{\color{blue}{2}}\right) \]
    3. Applied rewrites6.1%

      \[\leadsto \color{blue}{\cos \left(\left(z1 \cdot \pi\right) \cdot z0 + \frac{\pi}{2}\right)} \]
    4. Taylor expanded in z1 around 0

      \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \pi\right)} \]
    5. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\mathsf{PI}\left(\right)}\right) \]
      2. lower-PI.f643.8%

        \[\leadsto \cos \left(0.5 \cdot \pi\right) \]
    6. Applied rewrites3.8%

      \[\leadsto \cos \color{blue}{\left(0.5 \cdot \pi\right)} \]
    7. Evaluated real constant3.8%

      \[\leadsto \cos 1.5707963267948966 \]
    8. Step-by-step derivation
      1. lift-cos.f64N/A

        \[\leadsto \color{blue}{\cos \frac{884279719003555}{562949953421312}} \]
      2. cos-neg-revN/A

        \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(\frac{884279719003555}{562949953421312}\right)\right)} \]
      3. sin-+PI/2-revN/A

        \[\leadsto \color{blue}{\sin \left(\left(\mathsf{neg}\left(\frac{884279719003555}{562949953421312}\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right)} \]
      4. lower-sin.f64N/A

        \[\leadsto \color{blue}{\sin \left(\left(\mathsf{neg}\left(\frac{884279719003555}{562949953421312}\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right)} \]
      5. lift-PI.f64N/A

        \[\leadsto \sin \left(\left(\mathsf{neg}\left(\frac{884279719003555}{562949953421312}\right)\right) + \frac{\color{blue}{\pi}}{2}\right) \]
      6. mult-flipN/A

        \[\leadsto \sin \left(\left(\mathsf{neg}\left(\frac{884279719003555}{562949953421312}\right)\right) + \color{blue}{\pi \cdot \frac{1}{2}}\right) \]
      7. metadata-evalN/A

        \[\leadsto \sin \left(\left(\mathsf{neg}\left(\frac{884279719003555}{562949953421312}\right)\right) + \pi \cdot \color{blue}{\frac{1}{2}}\right) \]
      8. *-commutativeN/A

        \[\leadsto \sin \left(\left(\mathsf{neg}\left(\frac{884279719003555}{562949953421312}\right)\right) + \color{blue}{\frac{1}{2} \cdot \pi}\right) \]
      9. fp-cancel-sign-sub-invN/A

        \[\leadsto \sin \color{blue}{\left(\left(\mathsf{neg}\left(\frac{884279719003555}{562949953421312}\right)\right) - \left(\mathsf{neg}\left(\frac{1}{2}\right)\right) \cdot \pi\right)} \]
      10. metadata-evalN/A

        \[\leadsto \sin \left(\left(\mathsf{neg}\left(\frac{884279719003555}{562949953421312}\right)\right) - \color{blue}{\frac{-1}{2}} \cdot \pi\right) \]
      11. lift-*.f64N/A

        \[\leadsto \sin \left(\left(\mathsf{neg}\left(\frac{884279719003555}{562949953421312}\right)\right) - \color{blue}{\frac{-1}{2} \cdot \pi}\right) \]
      12. lower--.f64N/A

        \[\leadsto \sin \color{blue}{\left(\left(\mathsf{neg}\left(\frac{884279719003555}{562949953421312}\right)\right) - \frac{-1}{2} \cdot \pi\right)} \]
      13. lower-neg.f6459.1%

        \[\leadsto \sin \left(\color{blue}{\left(-1.5707963267948966\right)} - -0.5 \cdot \pi\right) \]
    9. Applied rewrites59.1%

      \[\leadsto \color{blue}{\sin \left(\left(-1.5707963267948966\right) - -0.5 \cdot \pi\right)} \]

    if -2.0000000000000001e32 < (*.f64 (PI.f64) (*.f64 z1 (neg.f64 z0)))

    1. Initial program 52.1%

      \[\sin \left(\pi \cdot \left(z1 \cdot \left(-z0\right)\right)\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \sin \color{blue}{\left(\pi \cdot \left(z1 \cdot \left(-z0\right)\right)\right)} \]
      2. *-commutativeN/A

        \[\leadsto \sin \color{blue}{\left(\left(z1 \cdot \left(-z0\right)\right) \cdot \pi\right)} \]
      3. lift-*.f64N/A

        \[\leadsto \sin \left(\color{blue}{\left(z1 \cdot \left(-z0\right)\right)} \cdot \pi\right) \]
      4. *-commutativeN/A

        \[\leadsto \sin \left(\color{blue}{\left(\left(-z0\right) \cdot z1\right)} \cdot \pi\right) \]
      5. associate-*l*N/A

        \[\leadsto \sin \color{blue}{\left(\left(-z0\right) \cdot \left(z1 \cdot \pi\right)\right)} \]
      6. *-commutativeN/A

        \[\leadsto \sin \left(\left(-z0\right) \cdot \color{blue}{\left(\pi \cdot z1\right)}\right) \]
      7. lift-PI.f64N/A

        \[\leadsto \sin \left(\left(-z0\right) \cdot \left(\color{blue}{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
      8. add-cube-cbrtN/A

        \[\leadsto \sin \left(\left(-z0\right) \cdot \left(\color{blue}{\left(\left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right) \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right)} \cdot z1\right)\right) \]
      9. associate-*l*N/A

        \[\leadsto \sin \left(\left(-z0\right) \cdot \color{blue}{\left(\left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right)}\right) \]
      10. associate-*r*N/A

        \[\leadsto \sin \color{blue}{\left(\left(\left(-z0\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right)\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right)} \]
      11. lower-*.f64N/A

        \[\leadsto \sin \color{blue}{\left(\left(\left(-z0\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right)\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right)} \]
      12. *-commutativeN/A

        \[\leadsto \sin \left(\color{blue}{\left(\left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right) \cdot \left(-z0\right)\right)} \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
      13. lower-*.f64N/A

        \[\leadsto \sin \left(\color{blue}{\left(\left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right) \cdot \left(-z0\right)\right)} \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
      14. lift-PI.f64N/A

        \[\leadsto \sin \left(\left(\left(\sqrt[3]{\color{blue}{\pi}} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right) \cdot \left(-z0\right)\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
      15. pow1/3N/A

        \[\leadsto \sin \left(\left(\left(\color{blue}{{\pi}^{\frac{1}{3}}} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right) \cdot \left(-z0\right)\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
      16. lift-PI.f64N/A

        \[\leadsto \sin \left(\left(\left({\pi}^{\frac{1}{3}} \cdot \sqrt[3]{\color{blue}{\pi}}\right) \cdot \left(-z0\right)\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
      17. pow1/3N/A

        \[\leadsto \sin \left(\left(\left({\pi}^{\frac{1}{3}} \cdot \color{blue}{{\pi}^{\frac{1}{3}}}\right) \cdot \left(-z0\right)\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
      18. pow-prod-upN/A

        \[\leadsto \sin \left(\left(\color{blue}{{\pi}^{\left(\frac{1}{3} + \frac{1}{3}\right)}} \cdot \left(-z0\right)\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
      19. lower-pow.f64N/A

        \[\leadsto \sin \left(\left(\color{blue}{{\pi}^{\left(\frac{1}{3} + \frac{1}{3}\right)}} \cdot \left(-z0\right)\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
      20. metadata-evalN/A

        \[\leadsto \sin \left(\left({\pi}^{\color{blue}{\frac{2}{3}}} \cdot \left(-z0\right)\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
    3. Applied rewrites51.8%

      \[\leadsto \sin \color{blue}{\left(\left({\pi}^{0.6666666666666666} \cdot \left(-z0\right)\right) \cdot \left(\sqrt[3]{\pi} \cdot z1\right)\right)} \]
    4. Evaluated real constant51.8%

      \[\leadsto \sin \left(\left(\color{blue}{2.1450293971110255} \cdot \left(-z0\right)\right) \cdot \left(\sqrt[3]{\pi} \cdot z1\right)\right) \]
    5. Evaluated real constant52.2%

      \[\leadsto \sin \left(\left(2.1450293971110255 \cdot \left(-z0\right)\right) \cdot \left(\color{blue}{1.4645918875615234} \cdot z1\right)\right) \]
    6. Taylor expanded in z1 around 0

      \[\leadsto \sin \color{blue}{\left(\frac{-3982441812995697399929051632117}{1267650600228229401496703205376} \cdot \left(z0 \cdot z1\right)\right)} \]
    7. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \sin \left(\frac{-3982441812995697399929051632117}{1267650600228229401496703205376} \cdot \color{blue}{\left(z0 \cdot z1\right)}\right) \]
      2. lower-*.f6452.1%

        \[\leadsto \sin \left(-3.141592653589793 \cdot \left(z0 \cdot \color{blue}{z1}\right)\right) \]
    8. Applied rewrites52.1%

      \[\leadsto \sin \color{blue}{\left(-3.141592653589793 \cdot \left(z0 \cdot z1\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 52.1% accurate, 1.0× speedup?

\[\sin \left(-3.141592653589793 \cdot \left(z0 \cdot z1\right)\right) \]
(FPCore (z1 z0)
  :precision binary64
  (sin (* -3.141592653589793 (* z0 z1))))
double code(double z1, double z0) {
	return sin((-3.141592653589793 * (z0 * z1)));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(z1, z0)
use fmin_fmax_functions
    real(8), intent (in) :: z1
    real(8), intent (in) :: z0
    code = sin(((-3.141592653589793d0) * (z0 * z1)))
end function
public static double code(double z1, double z0) {
	return Math.sin((-3.141592653589793 * (z0 * z1)));
}
def code(z1, z0):
	return math.sin((-3.141592653589793 * (z0 * z1)))
function code(z1, z0)
	return sin(Float64(-3.141592653589793 * Float64(z0 * z1)))
end
function tmp = code(z1, z0)
	tmp = sin((-3.141592653589793 * (z0 * z1)));
end
code[z1_, z0_] := N[Sin[N[(-3.141592653589793 * N[(z0 * z1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\sin \left(-3.141592653589793 \cdot \left(z0 \cdot z1\right)\right)
Derivation
  1. Initial program 52.1%

    \[\sin \left(\pi \cdot \left(z1 \cdot \left(-z0\right)\right)\right) \]
  2. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \sin \color{blue}{\left(\pi \cdot \left(z1 \cdot \left(-z0\right)\right)\right)} \]
    2. *-commutativeN/A

      \[\leadsto \sin \color{blue}{\left(\left(z1 \cdot \left(-z0\right)\right) \cdot \pi\right)} \]
    3. lift-*.f64N/A

      \[\leadsto \sin \left(\color{blue}{\left(z1 \cdot \left(-z0\right)\right)} \cdot \pi\right) \]
    4. *-commutativeN/A

      \[\leadsto \sin \left(\color{blue}{\left(\left(-z0\right) \cdot z1\right)} \cdot \pi\right) \]
    5. associate-*l*N/A

      \[\leadsto \sin \color{blue}{\left(\left(-z0\right) \cdot \left(z1 \cdot \pi\right)\right)} \]
    6. *-commutativeN/A

      \[\leadsto \sin \left(\left(-z0\right) \cdot \color{blue}{\left(\pi \cdot z1\right)}\right) \]
    7. lift-PI.f64N/A

      \[\leadsto \sin \left(\left(-z0\right) \cdot \left(\color{blue}{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
    8. add-cube-cbrtN/A

      \[\leadsto \sin \left(\left(-z0\right) \cdot \left(\color{blue}{\left(\left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right) \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right)} \cdot z1\right)\right) \]
    9. associate-*l*N/A

      \[\leadsto \sin \left(\left(-z0\right) \cdot \color{blue}{\left(\left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right)}\right) \]
    10. associate-*r*N/A

      \[\leadsto \sin \color{blue}{\left(\left(\left(-z0\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right)\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right)} \]
    11. lower-*.f64N/A

      \[\leadsto \sin \color{blue}{\left(\left(\left(-z0\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right)\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right)} \]
    12. *-commutativeN/A

      \[\leadsto \sin \left(\color{blue}{\left(\left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right) \cdot \left(-z0\right)\right)} \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
    13. lower-*.f64N/A

      \[\leadsto \sin \left(\color{blue}{\left(\left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right) \cdot \left(-z0\right)\right)} \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
    14. lift-PI.f64N/A

      \[\leadsto \sin \left(\left(\left(\sqrt[3]{\color{blue}{\pi}} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right) \cdot \left(-z0\right)\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
    15. pow1/3N/A

      \[\leadsto \sin \left(\left(\left(\color{blue}{{\pi}^{\frac{1}{3}}} \cdot \sqrt[3]{\mathsf{PI}\left(\right)}\right) \cdot \left(-z0\right)\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
    16. lift-PI.f64N/A

      \[\leadsto \sin \left(\left(\left({\pi}^{\frac{1}{3}} \cdot \sqrt[3]{\color{blue}{\pi}}\right) \cdot \left(-z0\right)\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
    17. pow1/3N/A

      \[\leadsto \sin \left(\left(\left({\pi}^{\frac{1}{3}} \cdot \color{blue}{{\pi}^{\frac{1}{3}}}\right) \cdot \left(-z0\right)\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
    18. pow-prod-upN/A

      \[\leadsto \sin \left(\left(\color{blue}{{\pi}^{\left(\frac{1}{3} + \frac{1}{3}\right)}} \cdot \left(-z0\right)\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
    19. lower-pow.f64N/A

      \[\leadsto \sin \left(\left(\color{blue}{{\pi}^{\left(\frac{1}{3} + \frac{1}{3}\right)}} \cdot \left(-z0\right)\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
    20. metadata-evalN/A

      \[\leadsto \sin \left(\left({\pi}^{\color{blue}{\frac{2}{3}}} \cdot \left(-z0\right)\right) \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot z1\right)\right) \]
  3. Applied rewrites51.8%

    \[\leadsto \sin \color{blue}{\left(\left({\pi}^{0.6666666666666666} \cdot \left(-z0\right)\right) \cdot \left(\sqrt[3]{\pi} \cdot z1\right)\right)} \]
  4. Evaluated real constant51.8%

    \[\leadsto \sin \left(\left(\color{blue}{2.1450293971110255} \cdot \left(-z0\right)\right) \cdot \left(\sqrt[3]{\pi} \cdot z1\right)\right) \]
  5. Evaluated real constant52.2%

    \[\leadsto \sin \left(\left(2.1450293971110255 \cdot \left(-z0\right)\right) \cdot \left(\color{blue}{1.4645918875615234} \cdot z1\right)\right) \]
  6. Taylor expanded in z1 around 0

    \[\leadsto \sin \color{blue}{\left(\frac{-3982441812995697399929051632117}{1267650600228229401496703205376} \cdot \left(z0 \cdot z1\right)\right)} \]
  7. Step-by-step derivation
    1. lower-*.f64N/A

      \[\leadsto \sin \left(\frac{-3982441812995697399929051632117}{1267650600228229401496703205376} \cdot \color{blue}{\left(z0 \cdot z1\right)}\right) \]
    2. lower-*.f6452.1%

      \[\leadsto \sin \left(-3.141592653589793 \cdot \left(z0 \cdot \color{blue}{z1}\right)\right) \]
  8. Applied rewrites52.1%

    \[\leadsto \sin \color{blue}{\left(-3.141592653589793 \cdot \left(z0 \cdot z1\right)\right)} \]
  9. Add Preprocessing

Alternative 3: 3.7% accurate, 0.5× speedup?

\[\mathsf{copysign}\left(1, z0\right) \cdot \cos 1.5707963267948966 \]
(FPCore (z1 z0)
  :precision binary64
  (* (copysign 1.0 z0) (cos 1.5707963267948966)))
double code(double z1, double z0) {
	return copysign(1.0, z0) * cos(1.5707963267948966);
}
public static double code(double z1, double z0) {
	return Math.copySign(1.0, z0) * Math.cos(1.5707963267948966);
}
def code(z1, z0):
	return math.copysign(1.0, z0) * math.cos(1.5707963267948966)
function code(z1, z0)
	return Float64(copysign(1.0, z0) * cos(1.5707963267948966))
end
function tmp = code(z1, z0)
	tmp = (sign(z0) * abs(1.0)) * cos(1.5707963267948966);
end
code[z1_, z0_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[z0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[Cos[1.5707963267948966], $MachinePrecision]), $MachinePrecision]
\mathsf{copysign}\left(1, z0\right) \cdot \cos 1.5707963267948966
Derivation
  1. Initial program 52.1%

    \[\sin \left(\pi \cdot \left(z1 \cdot \left(-z0\right)\right)\right) \]
  2. Step-by-step derivation
    1. lift-sin.f64N/A

      \[\leadsto \color{blue}{\sin \left(\pi \cdot \left(z1 \cdot \left(-z0\right)\right)\right)} \]
    2. lift-*.f64N/A

      \[\leadsto \sin \color{blue}{\left(\pi \cdot \left(z1 \cdot \left(-z0\right)\right)\right)} \]
    3. lift-*.f64N/A

      \[\leadsto \sin \left(\pi \cdot \color{blue}{\left(z1 \cdot \left(-z0\right)\right)}\right) \]
    4. associate-*r*N/A

      \[\leadsto \sin \color{blue}{\left(\left(\pi \cdot z1\right) \cdot \left(-z0\right)\right)} \]
    5. lift-neg.f64N/A

      \[\leadsto \sin \left(\left(\pi \cdot z1\right) \cdot \color{blue}{\left(\mathsf{neg}\left(z0\right)\right)}\right) \]
    6. distribute-rgt-neg-outN/A

      \[\leadsto \sin \color{blue}{\left(\mathsf{neg}\left(\left(\pi \cdot z1\right) \cdot z0\right)\right)} \]
    7. sin-negN/A

      \[\leadsto \color{blue}{\mathsf{neg}\left(\sin \left(\left(\pi \cdot z1\right) \cdot z0\right)\right)} \]
    8. cos-+PI/2-revN/A

      \[\leadsto \color{blue}{\cos \left(\left(\pi \cdot z1\right) \cdot z0 + \frac{\mathsf{PI}\left(\right)}{2}\right)} \]
    9. lower-cos.f64N/A

      \[\leadsto \color{blue}{\cos \left(\left(\pi \cdot z1\right) \cdot z0 + \frac{\mathsf{PI}\left(\right)}{2}\right)} \]
    10. lower-+.f64N/A

      \[\leadsto \cos \color{blue}{\left(\left(\pi \cdot z1\right) \cdot z0 + \frac{\mathsf{PI}\left(\right)}{2}\right)} \]
    11. lower-*.f64N/A

      \[\leadsto \cos \left(\color{blue}{\left(\pi \cdot z1\right) \cdot z0} + \frac{\mathsf{PI}\left(\right)}{2}\right) \]
    12. *-commutativeN/A

      \[\leadsto \cos \left(\color{blue}{\left(z1 \cdot \pi\right)} \cdot z0 + \frac{\mathsf{PI}\left(\right)}{2}\right) \]
    13. lower-*.f64N/A

      \[\leadsto \cos \left(\color{blue}{\left(z1 \cdot \pi\right)} \cdot z0 + \frac{\mathsf{PI}\left(\right)}{2}\right) \]
    14. lift-PI.f64N/A

      \[\leadsto \cos \left(\left(z1 \cdot \pi\right) \cdot z0 + \frac{\color{blue}{\pi}}{2}\right) \]
    15. metadata-evalN/A

      \[\leadsto \cos \left(\left(z1 \cdot \pi\right) \cdot z0 + \frac{\pi}{\color{blue}{1 + 1}}\right) \]
    16. lower-/.f64N/A

      \[\leadsto \cos \left(\left(z1 \cdot \pi\right) \cdot z0 + \color{blue}{\frac{\pi}{1 + 1}}\right) \]
    17. metadata-eval6.1%

      \[\leadsto \cos \left(\left(z1 \cdot \pi\right) \cdot z0 + \frac{\pi}{\color{blue}{2}}\right) \]
  3. Applied rewrites6.1%

    \[\leadsto \color{blue}{\cos \left(\left(z1 \cdot \pi\right) \cdot z0 + \frac{\pi}{2}\right)} \]
  4. Taylor expanded in z1 around 0

    \[\leadsto \cos \color{blue}{\left(\frac{1}{2} \cdot \pi\right)} \]
  5. Step-by-step derivation
    1. lower-*.f64N/A

      \[\leadsto \cos \left(\frac{1}{2} \cdot \color{blue}{\mathsf{PI}\left(\right)}\right) \]
    2. lower-PI.f643.8%

      \[\leadsto \cos \left(0.5 \cdot \pi\right) \]
  6. Applied rewrites3.8%

    \[\leadsto \cos \color{blue}{\left(0.5 \cdot \pi\right)} \]
  7. Evaluated real constant3.8%

    \[\leadsto \cos 1.5707963267948966 \]
  8. Add Preprocessing

Reproduce

?
herbie shell --seed 2025250 
(FPCore (z1 z0)
  :name "(sin (* PI (* z1 (- z0))))"
  :precision binary64
  (sin (* PI (* z1 (- z0)))))