
(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 7 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 (<= x -2.6e-72) (not (<= x 9e-95))) (fma (sin y) x (* 1.0 z)) (* (cos y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.6e-72) || !(x <= 9e-95)) {
tmp = fma(sin(y), x, (1.0 * z));
} else {
tmp = cos(y) * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -2.6e-72) || !(x <= 9e-95)) tmp = fma(sin(y), x, Float64(1.0 * z)); else tmp = Float64(cos(y) * z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.6e-72], N[Not[LessEqual[x, 9e-95]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] * x + N[(1.0 * z), $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{-72} \lor \neg \left(x \leq 9 \cdot 10^{-95}\right):\\
\;\;\;\;\mathsf{fma}\left(\sin y, x, 1 \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot z\\
\end{array}
\end{array}
if x < -2.59999999999999996e-72 or 9e-95 < x Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites89.3%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6489.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6489.3
Applied rewrites89.3%
if -2.59999999999999996e-72 < x < 9e-95Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6493.1
Applied rewrites93.1%
Final simplification90.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -2.7e+234)
t_0
(if (<= y -1.15e-7) (* (cos y) z) (if (<= y 8.5e-17) (fma y x z) t_0)))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (y <= -2.7e+234) {
tmp = t_0;
} else if (y <= -1.15e-7) {
tmp = cos(y) * z;
} else if (y <= 8.5e-17) {
tmp = fma(y, x, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (y <= -2.7e+234) tmp = t_0; elseif (y <= -1.15e-7) tmp = Float64(cos(y) * z); elseif (y <= 8.5e-17) tmp = fma(y, x, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.7e+234], t$95$0, If[LessEqual[y, -1.15e-7], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], If[LessEqual[y, 8.5e-17], N[(y * x + z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -2.7 \cdot 10^{+234}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.15 \cdot 10^{-7}:\\
\;\;\;\;\cos y \cdot z\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{-17}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.7000000000000002e234 or 8.5e-17 < y Initial program 99.6%
Applied rewrites24.9%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f645.7
Applied rewrites5.7%
Taylor expanded in x around inf
lower-*.f64N/A
lower-sin.f6468.8
Applied rewrites68.8%
if -2.7000000000000002e234 < y < -1.14999999999999997e-7Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6465.3
Applied rewrites65.3%
if -1.14999999999999997e-7 < y < 8.5e-17Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0115) (not (<= y 12000000.0))) (* (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.0115) || !(y <= 12000000.0)) {
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.0115) || !(y <= 12000000.0)) 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.0115], N[Not[LessEqual[y, 12000000.0]], $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.0115 \lor \neg \left(y \leq 12000000\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.0115 or 1.2e7 < y Initial program 99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6447.9
Applied rewrites47.9%
if -0.0115 < y < 1.2e7Initial 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-*.f6499.3
Applied rewrites99.3%
Final simplification73.0%
(FPCore (x y z) :precision binary64 (if (<= y -7900000000.0) (- z) (* x y)))
double code(double x, double y, double z) {
double tmp;
if (y <= -7900000000.0) {
tmp = -z;
} else {
tmp = x * y;
}
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 (y <= (-7900000000.0d0)) then
tmp = -z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -7900000000.0) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7900000000.0: tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7900000000.0) tmp = Float64(-z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -7900000000.0) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7900000000.0], (-z), N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7900000000:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -7.9e9Initial program 99.8%
Applied rewrites16.6%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f649.0
Applied rewrites9.0%
if -7.9e9 < y Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6471.1
Applied rewrites71.1%
Taylor expanded in x around inf
Applied rewrites19.6%
(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.f6451.6
Applied rewrites51.6%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 99.8%
Applied rewrites16.1%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f644.9
Applied rewrites4.9%
herbie shell --seed 2024339
(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))))