
(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}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 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}
\\
\left(x + \sin y\right) + 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 + x\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.36e-11) (not (<= x 4.3e-48))) (* (- x) (fma (/ (* (cos y) z) x) -1.0 -1.0)) (+ (sin y) (* z (cos y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.36e-11) || !(x <= 4.3e-48)) {
tmp = -x * fma(((cos(y) * z) / x), -1.0, -1.0);
} else {
tmp = sin(y) + (z * cos(y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -1.36e-11) || !(x <= 4.3e-48)) tmp = Float64(Float64(-x) * fma(Float64(Float64(cos(y) * z) / x), -1.0, -1.0)); else tmp = Float64(sin(y) + Float64(z * cos(y))); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.36e-11], N[Not[LessEqual[x, 4.3e-48]], $MachinePrecision]], N[((-x) * N[(N[(N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision] / x), $MachinePrecision] * -1.0 + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.36 \cdot 10^{-11} \lor \neg \left(x \leq 4.3 \cdot 10^{-48}\right):\\
\;\;\;\;\left(-x\right) \cdot \mathsf{fma}\left(\frac{\cos y \cdot z}{x}, -1, -1\right)\\
\mathbf{else}:\\
\;\;\;\;\sin y + z \cdot \cos y\\
\end{array}
\end{array}
if x < -1.36e-11 or 4.3e-48 < x Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Taylor expanded in x around -inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-sin.f6499.9
Applied rewrites99.9%
Taylor expanded in z around inf
Applied rewrites98.8%
if -1.36e-11 < x < 4.3e-48Initial program 99.9%
Taylor expanded in x around 0
lower-sin.f6497.1
Applied rewrites97.1%
Final simplification98.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.36e-11) (not (<= x 4.3e-48))) (* (- x) (fma (/ (* (cos y) z) x) -1.0 -1.0)) (fma (cos y) z (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.36e-11) || !(x <= 4.3e-48)) {
tmp = -x * fma(((cos(y) * z) / x), -1.0, -1.0);
} else {
tmp = fma(cos(y), z, sin(y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -1.36e-11) || !(x <= 4.3e-48)) tmp = Float64(Float64(-x) * fma(Float64(Float64(cos(y) * z) / x), -1.0, -1.0)); else tmp = fma(cos(y), z, sin(y)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.36e-11], N[Not[LessEqual[x, 4.3e-48]], $MachinePrecision]], N[((-x) * N[(N[(N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision] / x), $MachinePrecision] * -1.0 + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * z + N[Sin[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.36 \cdot 10^{-11} \lor \neg \left(x \leq 4.3 \cdot 10^{-48}\right):\\
\;\;\;\;\left(-x\right) \cdot \mathsf{fma}\left(\frac{\cos y \cdot z}{x}, -1, -1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos y, z, \sin y\right)\\
\end{array}
\end{array}
if x < -1.36e-11 or 4.3e-48 < x Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Taylor expanded in x around -inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-sin.f6499.9
Applied rewrites99.9%
Taylor expanded in z around inf
Applied rewrites98.8%
if -1.36e-11 < x < 4.3e-48Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-sin.f6497.1
Applied rewrites97.1%
Final simplification98.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) z)) (t_1 (* (- x) (fma (/ t_0 x) -1.0 -1.0))))
(if (<= z -5.3e+151)
t_0
(if (<= z -520.0)
t_1
(if (<= z 3.8e-24)
(fma 1.0 z (+ (sin y) x))
(if (<= z 2.05e+117) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = cos(y) * z;
double t_1 = -x * fma((t_0 / x), -1.0, -1.0);
double tmp;
if (z <= -5.3e+151) {
tmp = t_0;
} else if (z <= -520.0) {
tmp = t_1;
} else if (z <= 3.8e-24) {
tmp = fma(1.0, z, (sin(y) + x));
} else if (z <= 2.05e+117) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * z) t_1 = Float64(Float64(-x) * fma(Float64(t_0 / x), -1.0, -1.0)) tmp = 0.0 if (z <= -5.3e+151) tmp = t_0; elseif (z <= -520.0) tmp = t_1; elseif (z <= 3.8e-24) tmp = fma(1.0, z, Float64(sin(y) + x)); elseif (z <= 2.05e+117) tmp = t_1; else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]}, Block[{t$95$1 = N[((-x) * N[(N[(t$95$0 / x), $MachinePrecision] * -1.0 + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -5.3e+151], t$95$0, If[LessEqual[z, -520.0], t$95$1, If[LessEqual[z, 3.8e-24], N[(1.0 * z + N[(N[Sin[y], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.05e+117], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot z\\
t_1 := \left(-x\right) \cdot \mathsf{fma}\left(\frac{t\_0}{x}, -1, -1\right)\\
\mathbf{if}\;z \leq -5.3 \cdot 10^{+151}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -520:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 3.8 \cdot 10^{-24}:\\
\;\;\;\;\mathsf{fma}\left(1, z, \sin y + x\right)\\
\mathbf{elif}\;z \leq 2.05 \cdot 10^{+117}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.29999999999999999e151 or 2.05e117 < z 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%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6493.4
Applied rewrites93.4%
if -5.29999999999999999e151 < z < -520 or 3.80000000000000026e-24 < z < 2.05e117Initial 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 x around -inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-sin.f6498.2
Applied rewrites98.2%
Taylor expanded in z around inf
Applied rewrites95.9%
if -520 < z < 3.80000000000000026e-24Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) z)))
(if (<= x -3.2)
(+ z x)
(if (<= x -2.6e-197)
t_0
(if (<= x 1.25e-305)
(fma 1.0 z (sin y))
(if (<= x 2.6e-49) t_0 (+ z x)))))))
double code(double x, double y, double z) {
double t_0 = cos(y) * z;
double tmp;
if (x <= -3.2) {
tmp = z + x;
} else if (x <= -2.6e-197) {
tmp = t_0;
} else if (x <= 1.25e-305) {
tmp = fma(1.0, z, sin(y));
} else if (x <= 2.6e-49) {
tmp = t_0;
} else {
tmp = z + x;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * z) tmp = 0.0 if (x <= -3.2) tmp = Float64(z + x); elseif (x <= -2.6e-197) tmp = t_0; elseif (x <= 1.25e-305) tmp = fma(1.0, z, sin(y)); elseif (x <= 2.6e-49) tmp = t_0; else tmp = Float64(z + x); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[x, -3.2], N[(z + x), $MachinePrecision], If[LessEqual[x, -2.6e-197], t$95$0, If[LessEqual[x, 1.25e-305], N[(1.0 * z + N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.6e-49], t$95$0, N[(z + x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot z\\
\mathbf{if}\;x \leq -3.2:\\
\;\;\;\;z + x\\
\mathbf{elif}\;x \leq -2.6 \cdot 10^{-197}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{-305}:\\
\;\;\;\;\mathsf{fma}\left(1, z, \sin y\right)\\
\mathbf{elif}\;x \leq 2.6 \cdot 10^{-49}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;z + x\\
\end{array}
\end{array}
if x < -3.2000000000000002 or 2.59999999999999995e-49 < x Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6487.1
Applied rewrites87.1%
if -3.2000000000000002 < x < -2.6000000000000001e-197 or 1.24999999999999996e-305 < x < 2.59999999999999995e-49Initial 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 z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6471.0
Applied rewrites71.0%
if -2.6000000000000001e-197 < x < 1.24999999999999996e-305Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-sin.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
Applied rewrites87.2%
Final simplification82.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.5e+169) (not (<= z 1.18e+116))) (* (cos y) z) (fma 1.0 z (+ (sin y) x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e+169) || !(z <= 1.18e+116)) {
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 <= -6.5e+169) || !(z <= 1.18e+116)) 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, -6.5e+169], N[Not[LessEqual[z, 1.18e+116]], $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 -6.5 \cdot 10^{+169} \lor \neg \left(z \leq 1.18 \cdot 10^{+116}\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, z, \sin y + x\right)\\
\end{array}
\end{array}
if z < -6.4999999999999995e169 or 1.1799999999999999e116 < z Initial 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 z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6494.4
Applied rewrites94.4%
if -6.4999999999999995e169 < z < 1.1799999999999999e116Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
Applied rewrites90.3%
Final simplification91.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.5e+169) (not (<= z 1.18e+116))) (* (cos y) z) (+ z x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e+169) || !(z <= 1.18e+116)) {
tmp = cos(y) * z;
} else {
tmp = z + 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 <= (-6.5d+169)) .or. (.not. (z <= 1.18d+116))) then
tmp = cos(y) * z
else
tmp = z + x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e+169) || !(z <= 1.18e+116)) {
tmp = Math.cos(y) * z;
} else {
tmp = z + x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.5e+169) or not (z <= 1.18e+116): tmp = math.cos(y) * z else: tmp = z + x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.5e+169) || !(z <= 1.18e+116)) tmp = Float64(cos(y) * z); else tmp = Float64(z + x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -6.5e+169) || ~((z <= 1.18e+116))) tmp = cos(y) * z; else tmp = z + x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.5e+169], N[Not[LessEqual[z, 1.18e+116]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{+169} \lor \neg \left(z \leq 1.18 \cdot 10^{+116}\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;z + x\\
\end{array}
\end{array}
if z < -6.4999999999999995e169 or 1.1799999999999999e116 < z Initial 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 z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6494.4
Applied rewrites94.4%
if -6.4999999999999995e169 < z < 1.1799999999999999e116Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6473.4
Applied rewrites73.4%
Final simplification78.7%
(FPCore (x y z) :precision binary64 (+ z x))
double code(double x, double y, double z) {
return z + x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + x
end function
public static double code(double x, double y, double z) {
return z + x;
}
def code(x, y, z): return z + x
function code(x, y, z) return Float64(z + x) end
function tmp = code(x, y, z) tmp = z + x; end
code[x_, y_, z_] := N[(z + x), $MachinePrecision]
\begin{array}{l}
\\
z + x
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6466.9
Applied rewrites66.9%
Final simplification66.9%
(FPCore (x y z) :precision binary64 (+ z y))
double code(double x, double y, double z) {
return z + y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + y
end function
public static double code(double x, double y, double z) {
return z + y;
}
def code(x, y, z): return z + y
function code(x, y, z) return Float64(z + y) end
function tmp = code(x, y, z) tmp = z + y; end
code[x_, y_, z_] := N[(z + y), $MachinePrecision]
\begin{array}{l}
\\
z + y
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-sin.f6456.1
Applied rewrites56.1%
Taylor expanded in y around 0
Applied rewrites25.0%
Final simplification25.0%
herbie shell --seed 2024313
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, C"
:precision binary64
(+ (+ x (sin y)) (* z (cos y))))