
(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 (* z (cos y))))
(if (<= z -4.5e+129)
t_0
(if (<= z 470000000.0) (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 <= -4.5e+129) {
tmp = t_0;
} else if (z <= 470000000.0) {
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 <= -4.5e+129) tmp = t_0; elseif (z <= 470000000.0) 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, -4.5e+129], t$95$0, If[LessEqual[z, 470000000.0], 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 -4.5 \cdot 10^{+129}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 470000000:\\
\;\;\;\;\mathsf{fma}\left(1, z, x \cdot \sin y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -4.5000000000000001e129 or 4.7e8 < z Initial program 99.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6483.3
Applied rewrites83.3%
if -4.5000000000000001e129 < z < 4.7e8Initial 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 rewrites90.1%
Final simplification87.3%
(FPCore (x y z)
:precision binary64
(if (<= y -0.45)
(* z (cos y))
(if (<= y 90000.0)
(fma (fma (* (* x y) -0.16666666666666666) y x) y z)
(* x (sin y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.45) {
tmp = z * cos(y);
} else if (y <= 90000.0) {
tmp = fma(fma(((x * y) * -0.16666666666666666), y, x), y, z);
} else {
tmp = x * sin(y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -0.45) tmp = Float64(z * cos(y)); elseif (y <= 90000.0) tmp = fma(fma(Float64(Float64(x * y) * -0.16666666666666666), y, x), y, z); else tmp = Float64(x * sin(y)); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -0.45], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 90000.0], N[(N[(N[(N[(x * y), $MachinePrecision] * -0.16666666666666666), $MachinePrecision] * y + x), $MachinePrecision] * y + z), $MachinePrecision], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.45:\\
\;\;\;\;z \cdot \cos y\\
\mathbf{elif}\;y \leq 90000:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\left(x \cdot y\right) \cdot -0.16666666666666666, y, x\right), y, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y\\
\end{array}
\end{array}
if y < -0.450000000000000011Initial program 99.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6460.5
Applied rewrites60.5%
if -0.450000000000000011 < y < 9e4Initial program 100.0%
lift-+.f64N/A
flip-+N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip-+N/A
lift-+.f64N/A
inv-powN/A
lower-pow.f6499.7
Applied rewrites99.7%
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-*.f6498.8
Applied rewrites98.8%
Taylor expanded in z around 0
Applied rewrites99.0%
if 9e4 < y Initial program 99.6%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6461.3
Applied rewrites61.3%
Final simplification81.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= y -0.45)
t_0
(if (<= y 0.11)
(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 <= -0.45) {
tmp = t_0;
} else if (y <= 0.11) {
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 <= -0.45) tmp = t_0; elseif (y <= 0.11) 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, -0.45], t$95$0, If[LessEqual[y, 0.11], 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 -0.45:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.11:\\
\;\;\;\;\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 < -0.450000000000000011 or 0.110000000000000001 < y Initial program 99.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6450.9
Applied rewrites50.9%
if -0.450000000000000011 < y < 0.110000000000000001Initial 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.5
Applied rewrites99.5%
Final simplification76.4%
(FPCore (x y z) :precision binary64 (if (<= x -4.3e+210) (* x y) (if (<= x 2.2e+99) (* 1.0 z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.3e+210) {
tmp = x * y;
} else if (x <= 2.2e+99) {
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 <= (-4.3d+210)) then
tmp = x * y
else if (x <= 2.2d+99) 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 <= -4.3e+210) {
tmp = x * y;
} else if (x <= 2.2e+99) {
tmp = 1.0 * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.3e+210: tmp = x * y elif x <= 2.2e+99: tmp = 1.0 * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.3e+210) tmp = Float64(x * y); elseif (x <= 2.2e+99) 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 <= -4.3e+210) tmp = x * y; elseif (x <= 2.2e+99) tmp = 1.0 * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.3e+210], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.2e+99], N[(1.0 * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.3 \cdot 10^{+210}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{+99}:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -4.3e210 or 2.19999999999999978e99 < x Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6463.1
Applied rewrites63.1%
Taylor expanded in z around 0
Applied rewrites42.2%
if -4.3e210 < x < 2.19999999999999978e99Initial 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%
remove-double-divN/A
unpow-1N/A
lift-pow.f64N/A
inv-powN/A
sqr-powN/A
pow2N/A
lower-pow.f64N/A
Applied rewrites46.8%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-cos.f6495.5
Applied rewrites95.5%
Taylor expanded in y around 0
Applied rewrites44.5%
Final simplification43.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.f6454.7
Applied rewrites54.7%
(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.f6454.7
Applied rewrites54.7%
Taylor expanded in z around 0
Applied rewrites19.7%
Final simplification19.7%
herbie shell --seed 2024249
(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))))