
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma (cos y) z (* (sin y) x)))
double code(double x, double y, double z) {
return fma(cos(y), z, (sin(y) * x));
}
function code(x, y, z) return fma(cos(y), z, Float64(sin(y) * x)) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, \sin y \cdot x\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -8.6e+101) (not (<= z 4.8e+79))) (* (cos y) z) (fma 1.0 z (* (sin y) x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.6e+101) || !(z <= 4.8e+79)) {
tmp = cos(y) * z;
} else {
tmp = fma(1.0, z, (sin(y) * x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -8.6e+101) || !(z <= 4.8e+79)) tmp = Float64(cos(y) * z); else tmp = fma(1.0, z, Float64(sin(y) * x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -8.6e+101], N[Not[LessEqual[z, 4.8e+79]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(1.0 * z + N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.6 \cdot 10^{+101} \lor \neg \left(z \leq 4.8 \cdot 10^{+79}\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, z, \sin y \cdot x\right)\\
\end{array}
\end{array}
if z < -8.6000000000000002e101 or 4.79999999999999971e79 < z Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6490.9
Applied rewrites90.9%
if -8.6000000000000002e101 < z < 4.79999999999999971e79Initial program 99.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
Applied rewrites86.5%
Final simplification88.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -9.2e-132) (not (<= z 1.35e-35))) (* (cos y) z) (* (sin y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -9.2e-132) || !(z <= 1.35e-35)) {
tmp = cos(y) * z;
} else {
tmp = sin(y) * x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-9.2d-132)) .or. (.not. (z <= 1.35d-35))) then
tmp = cos(y) * z
else
tmp = sin(y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -9.2e-132) || !(z <= 1.35e-35)) {
tmp = Math.cos(y) * z;
} else {
tmp = Math.sin(y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -9.2e-132) or not (z <= 1.35e-35): tmp = math.cos(y) * z else: tmp = math.sin(y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -9.2e-132) || !(z <= 1.35e-35)) tmp = Float64(cos(y) * z); else tmp = Float64(sin(y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -9.2e-132) || ~((z <= 1.35e-35))) tmp = cos(y) * z; else tmp = sin(y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -9.2e-132], N[Not[LessEqual[z, 1.35e-35]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.2 \cdot 10^{-132} \lor \neg \left(z \leq 1.35 \cdot 10^{-35}\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot x\\
\end{array}
\end{array}
if z < -9.20000000000000012e-132 or 1.3499999999999999e-35 < z Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6479.1
Applied rewrites79.1%
if -9.20000000000000012e-132 < z < 1.3499999999999999e-35Initial program 99.8%
lift-+.f64N/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
sqrt-prodN/A
lower-fma.f64N/A
lower-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f6459.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6459.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6459.2
Applied rewrites59.2%
Taylor expanded in x around -inf
mul-1-negN/A
*-commutativeN/A
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-lft-identityN/A
lower-*.f64N/A
lower-sin.f6476.4
Applied rewrites76.4%
Final simplification78.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00365) (not (<= y 8e-10))) (* (cos y) z) (fma (fma (fma -0.16666666666666666 (* y x) (* -0.5 z)) y x) y z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00365) || !(y <= 8e-10)) {
tmp = cos(y) * z;
} else {
tmp = fma(fma(fma(-0.16666666666666666, (y * x), (-0.5 * z)), y, x), y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -0.00365) || !(y <= 8e-10)) tmp = Float64(cos(y) * z); else tmp = fma(fma(fma(-0.16666666666666666, Float64(y * x), Float64(-0.5 * z)), y, x), y, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00365], N[Not[LessEqual[y, 8e-10]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(N[(N[(-0.16666666666666666 * N[(y * x), $MachinePrecision] + N[(-0.5 * z), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision] * y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00365 \lor \neg \left(y \leq 8 \cdot 10^{-10}\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, y \cdot x, -0.5 \cdot z\right), y, x\right), y, z\right)\\
\end{array}
\end{array}
if y < -0.00365000000000000003 or 8.00000000000000029e-10 < y Initial program 99.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6452.6
Applied rewrites52.6%
if -0.00365000000000000003 < y < 8.00000000000000029e-10Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
Final simplification76.3%
(FPCore (x y z) :precision binary64 (fma y x z))
double code(double x, double y, double z) {
return fma(y, x, z);
}
function code(x, y, z) return fma(y, x, z) end
code[x_, y_, z_] := N[(y * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, z\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6453.4
Applied rewrites53.4%
Final simplification53.4%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * y
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6453.4
Applied rewrites53.4%
Taylor expanded in x around inf
Applied rewrites19.5%
Final simplification19.5%
herbie shell --seed 2024337
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))