
(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 (* x (sin y))))
double code(double x, double y, double z) {
return fma(cos(y), z, (x * sin(y)));
}
function code(x, y, z) return fma(cos(y), z, Float64(x * sin(y))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, x \cdot \sin y\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%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))))
(if (<= y -3.6e+230)
(* z (cos y))
(if (<= y -0.0245)
t_0
(if (<= y 2e-9)
(fma (fma (fma -0.16666666666666666 (* x y) (* -0.5 z)) y x) y z)
t_0)))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (y <= -3.6e+230) {
tmp = z * cos(y);
} else if (y <= -0.0245) {
tmp = t_0;
} else if (y <= 2e-9) {
tmp = fma(fma(fma(-0.16666666666666666, (x * y), (-0.5 * z)), y, x), y, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (y <= -3.6e+230) tmp = Float64(z * cos(y)); elseif (y <= -0.0245) tmp = t_0; elseif (y <= 2e-9) tmp = fma(fma(fma(-0.16666666666666666, Float64(x * y), Float64(-0.5 * z)), y, x), y, 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, -3.6e+230], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -0.0245], t$95$0, If[LessEqual[y, 2e-9], N[(N[(N[(-0.16666666666666666 * N[(x * y), $MachinePrecision] + N[(-0.5 * z), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision] * y + z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -3.6 \cdot 10^{+230}:\\
\;\;\;\;z \cdot \cos y\\
\mathbf{elif}\;y \leq -0.0245:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, x \cdot y, -0.5 \cdot z\right), y, x\right), y, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.60000000000000019e230Initial program 99.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6469.9
Applied rewrites69.9%
if -3.60000000000000019e230 < y < -0.024500000000000001 or 2.00000000000000012e-9 < y Initial program 99.5%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6458.8
Applied rewrites58.8%
if -0.024500000000000001 < y < 2.00000000000000012e-9Initial 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 simplification79.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* z (cos y)))) (if (<= z -1e+207) t_0 (if (<= z 5.6e+151) (fma 1.0 z (* x (sin y))) t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -1e+207) {
tmp = t_0;
} else if (z <= 5.6e+151) {
tmp = fma(1.0, z, (x * sin(y)));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -1e+207) tmp = t_0; elseif (z <= 5.6e+151) tmp = fma(1.0, z, Float64(x * sin(y))); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1e+207], t$95$0, If[LessEqual[z, 5.6e+151], N[(1.0 * z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -1 \cdot 10^{+207}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 5.6 \cdot 10^{+151}:\\
\;\;\;\;\mathsf{fma}\left(1, z, x \cdot \sin y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1e207 or 5.59999999999999975e151 < z Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6498.5
Applied rewrites98.5%
if -1e207 < z < 5.59999999999999975e151Initial program 99.7%
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 rewrites85.7%
Final simplification88.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= y -2.2)
t_0
(if (<= y 0.031)
(fma (fma (fma -0.16666666666666666 (* x y) (* -0.5 z)) y x) y z)
t_0))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (y <= -2.2) {
tmp = t_0;
} else if (y <= 0.031) {
tmp = fma(fma(fma(-0.16666666666666666, (x * y), (-0.5 * z)), y, x), y, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (y <= -2.2) tmp = t_0; elseif (y <= 0.031) tmp = fma(fma(fma(-0.16666666666666666, Float64(x * y), Float64(-0.5 * z)), y, x), y, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.2], t$95$0, If[LessEqual[y, 0.031], N[(N[(N[(-0.16666666666666666 * N[(x * y), $MachinePrecision] + N[(-0.5 * z), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision] * y + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;y \leq -2.2:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.031:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, x \cdot y, -0.5 \cdot z\right), y, x\right), y, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.2000000000000002 or 0.031 < y Initial program 99.5%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6446.1
Applied rewrites46.1%
if -2.2000000000000002 < y < 0.031Initial 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.1
Applied rewrites99.1%
Final simplification72.8%
(FPCore (x y z) :precision binary64 (if (<= x -1.25e+180) (* x y) (if (<= x 4.8e+166) (* 1.0 z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.25e+180) {
tmp = x * y;
} else if (x <= 4.8e+166) {
tmp = 1.0 * 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 (x <= (-1.25d+180)) then
tmp = x * y
else if (x <= 4.8d+166) then
tmp = 1.0d0 * z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.25e+180) {
tmp = x * y;
} else if (x <= 4.8e+166) {
tmp = 1.0 * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.25e+180: tmp = x * y elif x <= 4.8e+166: tmp = 1.0 * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.25e+180) tmp = Float64(x * y); elseif (x <= 4.8e+166) tmp = Float64(1.0 * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.25e+180) tmp = x * y; elseif (x <= 4.8e+166) tmp = 1.0 * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.25e+180], N[(x * y), $MachinePrecision], If[LessEqual[x, 4.8e+166], N[(1.0 * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{+180}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 4.8 \cdot 10^{+166}:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.2499999999999999e180 or 4.79999999999999984e166 < x Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6451.6
Applied rewrites51.6%
Taylor expanded in z around 0
Applied rewrites37.8%
if -1.2499999999999999e180 < x < 4.79999999999999984e166Initial program 99.7%
lift-+.f64N/A
flip3-+N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites36.2%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6470.4
Applied rewrites70.4%
Taylor expanded in y around 0
Applied rewrites46.9%
Final simplification44.8%
(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.f6452.6
Applied rewrites52.6%
(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.f6452.6
Applied rewrites52.6%
Taylor expanded in z around 0
Applied rewrites17.1%
Final simplification17.1%
herbie shell --seed 2024235
(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))))