
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x + cos(y)) - (z * sin(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 + cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x + math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x + cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x + cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \cos y\right) - z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (- (+ x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x + cos(y)) - (z * sin(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 + cos(y)) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.cos(y)) - (z * Math.sin(y));
}
def code(x, y, z): return (x + math.cos(y)) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x + cos(y)) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x + cos(y)) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x + N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \cos y\right) - z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (fma (sin y) (- z) (+ (cos y) x)))
double code(double x, double y, double z) {
return fma(sin(y), -z, (cos(y) + x));
}
function code(x, y, z) return fma(sin(y), Float64(-z), Float64(cos(y) + x)) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * (-z) + N[(N[Cos[y], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, -z, \cos y + x\right)
\end{array}
Initial program 99.9%
Taylor expanded in z around 0 99.9%
associate-+r+99.9%
associate-*r*99.9%
neg-mul-199.9%
*-commutative99.9%
+-commutative99.9%
fma-def99.9%
+-commutative99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (<= x -5.3e-11) (+ (cos y) x) (if (<= x 11000.0) (- (cos y) (* (sin y) z)) (+ x (- 1.0 (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.3e-11) {
tmp = cos(y) + x;
} else if (x <= 11000.0) {
tmp = cos(y) - (sin(y) * z);
} else {
tmp = x + (1.0 - (y * z));
}
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 <= (-5.3d-11)) then
tmp = cos(y) + x
else if (x <= 11000.0d0) then
tmp = cos(y) - (sin(y) * z)
else
tmp = x + (1.0d0 - (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5.3e-11) {
tmp = Math.cos(y) + x;
} else if (x <= 11000.0) {
tmp = Math.cos(y) - (Math.sin(y) * z);
} else {
tmp = x + (1.0 - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.3e-11: tmp = math.cos(y) + x elif x <= 11000.0: tmp = math.cos(y) - (math.sin(y) * z) else: tmp = x + (1.0 - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.3e-11) tmp = Float64(cos(y) + x); elseif (x <= 11000.0) tmp = Float64(cos(y) - Float64(sin(y) * z)); else tmp = Float64(x + Float64(1.0 - Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.3e-11) tmp = cos(y) + x; elseif (x <= 11000.0) tmp = cos(y) - (sin(y) * z); else tmp = x + (1.0 - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.3e-11], N[(N[Cos[y], $MachinePrecision] + x), $MachinePrecision], If[LessEqual[x, 11000.0], N[(N[Cos[y], $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.3 \cdot 10^{-11}:\\
\;\;\;\;\cos y + x\\
\mathbf{elif}\;x \leq 11000:\\
\;\;\;\;\cos y - \sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if x < -5.2999999999999998e-11Initial program 100.0%
Taylor expanded in z around 0 91.0%
+-commutative91.0%
Simplified91.0%
if -5.2999999999999998e-11 < x < 11000Initial program 99.9%
Taylor expanded in x around 0 98.3%
if 11000 < x Initial program 99.9%
Taylor expanded in y around 0 82.4%
associate-+r+82.4%
+-commutative82.4%
associate-+l+82.4%
mul-1-neg82.4%
unsub-neg82.4%
Simplified82.4%
Final simplification92.6%
(FPCore (x y z) :precision binary64 (- (+ (cos y) x) (* (sin y) z)))
double code(double x, double y, double z) {
return (cos(y) + x) - (sin(y) * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (cos(y) + x) - (sin(y) * z)
end function
public static double code(double x, double y, double z) {
return (Math.cos(y) + x) - (Math.sin(y) * z);
}
def code(x, y, z): return (math.cos(y) + x) - (math.sin(y) * z)
function code(x, y, z) return Float64(Float64(cos(y) + x) - Float64(sin(y) * z)) end
function tmp = code(x, y, z) tmp = (cos(y) + x) - (sin(y) * z); end
code[x_, y_, z_] := N[(N[(N[Cos[y], $MachinePrecision] + x), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\cos y + x\right) - \sin y \cdot z
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) (- z))))
(if (<= z -4.2e+161)
t_0
(if (<= z -2.9e+119)
(+ x (- 1.0 (* y z)))
(if (or (<= z -4e+115) (not (<= z 1.3e+149))) t_0 (+ (cos y) x))))))
double code(double x, double y, double z) {
double t_0 = sin(y) * -z;
double tmp;
if (z <= -4.2e+161) {
tmp = t_0;
} else if (z <= -2.9e+119) {
tmp = x + (1.0 - (y * z));
} else if ((z <= -4e+115) || !(z <= 1.3e+149)) {
tmp = t_0;
} else {
tmp = cos(y) + 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) :: t_0
real(8) :: tmp
t_0 = sin(y) * -z
if (z <= (-4.2d+161)) then
tmp = t_0
else if (z <= (-2.9d+119)) then
tmp = x + (1.0d0 - (y * z))
else if ((z <= (-4d+115)) .or. (.not. (z <= 1.3d+149))) then
tmp = t_0
else
tmp = cos(y) + x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.sin(y) * -z;
double tmp;
if (z <= -4.2e+161) {
tmp = t_0;
} else if (z <= -2.9e+119) {
tmp = x + (1.0 - (y * z));
} else if ((z <= -4e+115) || !(z <= 1.3e+149)) {
tmp = t_0;
} else {
tmp = Math.cos(y) + x;
}
return tmp;
}
def code(x, y, z): t_0 = math.sin(y) * -z tmp = 0 if z <= -4.2e+161: tmp = t_0 elif z <= -2.9e+119: tmp = x + (1.0 - (y * z)) elif (z <= -4e+115) or not (z <= 1.3e+149): tmp = t_0 else: tmp = math.cos(y) + x return tmp
function code(x, y, z) t_0 = Float64(sin(y) * Float64(-z)) tmp = 0.0 if (z <= -4.2e+161) tmp = t_0; elseif (z <= -2.9e+119) tmp = Float64(x + Float64(1.0 - Float64(y * z))); elseif ((z <= -4e+115) || !(z <= 1.3e+149)) tmp = t_0; else tmp = Float64(cos(y) + x); end return tmp end
function tmp_2 = code(x, y, z) t_0 = sin(y) * -z; tmp = 0.0; if (z <= -4.2e+161) tmp = t_0; elseif (z <= -2.9e+119) tmp = x + (1.0 - (y * z)); elseif ((z <= -4e+115) || ~((z <= 1.3e+149))) tmp = t_0; else tmp = cos(y) + x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]}, If[LessEqual[z, -4.2e+161], t$95$0, If[LessEqual[z, -2.9e+119], N[(x + N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[z, -4e+115], N[Not[LessEqual[z, 1.3e+149]], $MachinePrecision]], t$95$0, N[(N[Cos[y], $MachinePrecision] + x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -4.2 \cdot 10^{+161}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -2.9 \cdot 10^{+119}:\\
\;\;\;\;x + \left(1 - y \cdot z\right)\\
\mathbf{elif}\;z \leq -4 \cdot 10^{+115} \lor \neg \left(z \leq 1.3 \cdot 10^{+149}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\cos y + x\\
\end{array}
\end{array}
if z < -4.2e161 or -2.90000000000000007e119 < z < -4.0000000000000001e115 or 1.29999999999999989e149 < z Initial program 99.8%
Taylor expanded in z around inf 76.9%
associate-*r*76.9%
neg-mul-176.9%
*-commutative76.9%
Simplified76.9%
if -4.2e161 < z < -2.90000000000000007e119Initial program 99.8%
Taylor expanded in y around 0 84.7%
associate-+r+84.7%
+-commutative84.7%
associate-+l+84.7%
mul-1-neg84.7%
unsub-neg84.7%
Simplified84.7%
if -4.0000000000000001e115 < z < 1.29999999999999989e149Initial program 100.0%
Taylor expanded in z around 0 92.7%
+-commutative92.7%
Simplified92.7%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -235000.0) (not (<= y 1600000.0))) (+ (cos y) x) (+ x (- 1.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -235000.0) || !(y <= 1600000.0)) {
tmp = cos(y) + x;
} else {
tmp = x + (1.0 - (y * z));
}
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 <= (-235000.0d0)) .or. (.not. (y <= 1600000.0d0))) then
tmp = cos(y) + x
else
tmp = x + (1.0d0 - (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -235000.0) || !(y <= 1600000.0)) {
tmp = Math.cos(y) + x;
} else {
tmp = x + (1.0 - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -235000.0) or not (y <= 1600000.0): tmp = math.cos(y) + x else: tmp = x + (1.0 - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -235000.0) || !(y <= 1600000.0)) tmp = Float64(cos(y) + x); else tmp = Float64(x + Float64(1.0 - Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -235000.0) || ~((y <= 1600000.0))) tmp = cos(y) + x; else tmp = x + (1.0 - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -235000.0], N[Not[LessEqual[y, 1600000.0]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] + x), $MachinePrecision], N[(x + N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -235000 \lor \neg \left(y \leq 1600000\right):\\
\;\;\;\;\cos y + x\\
\mathbf{else}:\\
\;\;\;\;x + \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if y < -235000 or 1.6e6 < y Initial program 99.8%
Taylor expanded in z around 0 60.2%
+-commutative60.2%
Simplified60.2%
if -235000 < y < 1.6e6Initial program 100.0%
Taylor expanded in y around 0 98.1%
associate-+r+98.1%
+-commutative98.1%
associate-+l+98.1%
mul-1-neg98.1%
unsub-neg98.1%
Simplified98.1%
Final simplification80.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.6e+50) (not (<= y 6.2e+51))) (+ x 1.0) (+ x (- 1.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.6e+50) || !(y <= 6.2e+51)) {
tmp = x + 1.0;
} else {
tmp = x + (1.0 - (y * z));
}
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 <= (-2.6d+50)) .or. (.not. (y <= 6.2d+51))) then
tmp = x + 1.0d0
else
tmp = x + (1.0d0 - (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.6e+50) || !(y <= 6.2e+51)) {
tmp = x + 1.0;
} else {
tmp = x + (1.0 - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.6e+50) or not (y <= 6.2e+51): tmp = x + 1.0 else: tmp = x + (1.0 - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.6e+50) || !(y <= 6.2e+51)) tmp = Float64(x + 1.0); else tmp = Float64(x + Float64(1.0 - Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.6e+50) || ~((y <= 6.2e+51))) tmp = x + 1.0; else tmp = x + (1.0 - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.6e+50], N[Not[LessEqual[y, 6.2e+51]], $MachinePrecision]], N[(x + 1.0), $MachinePrecision], N[(x + N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{+50} \lor \neg \left(y \leq 6.2 \cdot 10^{+51}\right):\\
\;\;\;\;x + 1\\
\mathbf{else}:\\
\;\;\;\;x + \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if y < -2.6000000000000002e50 or 6.20000000000000022e51 < y Initial program 99.8%
Taylor expanded in y around 0 40.5%
+-commutative40.5%
Simplified40.5%
if -2.6000000000000002e50 < y < 6.20000000000000022e51Initial program 100.0%
Taylor expanded in y around 0 93.1%
associate-+r+93.1%
+-commutative93.1%
associate-+l+93.1%
mul-1-neg93.1%
unsub-neg93.1%
Simplified93.1%
Final simplification72.7%
(FPCore (x y z) :precision binary64 (+ x 1.0))
double code(double x, double y, double z) {
return x + 1.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + 1.0d0
end function
public static double code(double x, double y, double z) {
return x + 1.0;
}
def code(x, y, z): return x + 1.0
function code(x, y, z) return Float64(x + 1.0) end
function tmp = code(x, y, z) tmp = x + 1.0; end
code[x_, y_, z_] := N[(x + 1.0), $MachinePrecision]
\begin{array}{l}
\\
x + 1
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 62.8%
+-commutative62.8%
Simplified62.8%
Final simplification62.8%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.9%
Taylor expanded in x around inf 43.2%
Final simplification43.2%
herbie shell --seed 2024031
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, B"
:precision binary64
(- (+ x (cos y)) (* z (sin y))))