
(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 (sin y) x (* (cos y) z)))
double code(double x, double y, double z) {
return fma(sin(y), x, (cos(y) * z));
}
function code(x, y, z) return fma(sin(y), x, Float64(cos(y) * z)) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * x + N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, x, \cos y \cdot z\right)
\end{array}
Initial program 99.8%
lift-+.f64N/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 -3.5e-25) (not (<= x 2.05e-83))) (fma 1.0 z (* x (sin y))) (* (cos y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.5e-25) || !(x <= 2.05e-83)) {
tmp = fma(1.0, z, (x * sin(y)));
} else {
tmp = cos(y) * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -3.5e-25) || !(x <= 2.05e-83)) tmp = fma(1.0, z, Float64(x * sin(y))); else tmp = Float64(cos(y) * z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.5e-25], N[Not[LessEqual[x, 2.05e-83]], $MachinePrecision]], N[(1.0 * z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.5 \cdot 10^{-25} \lor \neg \left(x \leq 2.05 \cdot 10^{-83}\right):\\
\;\;\;\;\mathsf{fma}\left(1, z, x \cdot \sin y\right)\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot z\\
\end{array}
\end{array}
if x < -3.5000000000000002e-25 or 2.05e-83 < x Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites90.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lower-fma.f6490.0
lift-*.f64N/A
*-commutativeN/A
lift-*.f6490.0
Applied rewrites90.0%
if -3.5000000000000002e-25 < x < 2.05e-83Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6487.8
Applied rewrites87.8%
Final simplification89.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) x)))
(if (<= y -340.0)
t_0
(if (<= y 45000.0)
(fma (fma (* -0.5 y) z x) y z)
(if (<= y 3.1e+151) (* (cos y) z) t_0)))))
double code(double x, double y, double z) {
double t_0 = sin(y) * x;
double tmp;
if (y <= -340.0) {
tmp = t_0;
} else if (y <= 45000.0) {
tmp = fma(fma((-0.5 * y), z, x), y, z);
} else if (y <= 3.1e+151) {
tmp = cos(y) * z;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(sin(y) * x) tmp = 0.0 if (y <= -340.0) tmp = t_0; elseif (y <= 45000.0) tmp = fma(fma(Float64(-0.5 * y), z, x), y, z); elseif (y <= 3.1e+151) tmp = Float64(cos(y) * z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -340.0], t$95$0, If[LessEqual[y, 45000.0], N[(N[(N[(-0.5 * y), $MachinePrecision] * z + x), $MachinePrecision] * y + z), $MachinePrecision], If[LessEqual[y, 3.1e+151], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot x\\
\mathbf{if}\;y \leq -340:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 45000:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.5 \cdot y, z, x\right), y, z\right)\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{+151}:\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -340 or 3.1000000000000002e151 < y Initial program 99.6%
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.6
Applied rewrites99.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6485.8
Applied rewrites85.8%
Taylor expanded in x around inf
Applied rewrites59.9%
if -340 < y < 45000Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6498.7
Applied rewrites98.7%
if 45000 < y < 3.1000000000000002e151Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6470.4
Applied rewrites70.4%
Final simplification81.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0106) (not (<= y 45000.0))) (* (cos y) z) (fma (fma (* -0.5 y) z x) y z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0106) || !(y <= 45000.0)) {
tmp = cos(y) * z;
} else {
tmp = fma(fma((-0.5 * y), z, x), y, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -0.0106) || !(y <= 45000.0)) tmp = Float64(cos(y) * z); else tmp = fma(fma(Float64(-0.5 * y), z, x), y, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0106], N[Not[LessEqual[y, 45000.0]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(N[(N[(-0.5 * y), $MachinePrecision] * z + x), $MachinePrecision] * y + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0106 \lor \neg \left(y \leq 45000\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.5 \cdot y, z, x\right), y, z\right)\\
\end{array}
\end{array}
if y < -0.0106 or 45000 < y Initial program 99.7%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6449.8
Applied rewrites49.8%
if -0.0106 < y < 45000Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6499.3
Applied rewrites99.3%
Final simplification75.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.5e-187) (not (<= z 2.8e-125))) (* 1.0 z) (* x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e-187) || !(z <= 2.8e-125)) {
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 ((z <= (-6.5d-187)) .or. (.not. (z <= 2.8d-125))) 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 ((z <= -6.5e-187) || !(z <= 2.8e-125)) {
tmp = 1.0 * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.5e-187) or not (z <= 2.8e-125): tmp = 1.0 * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.5e-187) || !(z <= 2.8e-125)) 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 ((z <= -6.5e-187) || ~((z <= 2.8e-125))) tmp = 1.0 * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.5e-187], N[Not[LessEqual[z, 2.8e-125]], $MachinePrecision]], N[(1.0 * z), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{-187} \lor \neg \left(z \leq 2.8 \cdot 10^{-125}\right):\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if z < -6.49999999999999983e-187 or 2.8e-125 < z Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6475.0
Applied rewrites75.0%
Taylor expanded in y around 0
Applied rewrites51.7%
if -6.49999999999999983e-187 < z < 2.8e-125Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6439.0
Applied rewrites39.0%
Taylor expanded in x around inf
Applied rewrites30.7%
Final simplification47.7%
(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.9
Applied rewrites54.9%
Final simplification54.9%
(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.9
Applied rewrites54.9%
Taylor expanded in x around inf
Applied rewrites13.7%
Final simplification13.7%
herbie shell --seed 2024307
(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))))