
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (- (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) - z;
}
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 + z)) - z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) - z;
}
def code(x, y, z): return (x * (y + z)) - z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) - z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + z\right) - z
\end{array}
Initial program 98.8%
*-commutative98.8%
sub-neg98.8%
distribute-rgt-in98.8%
associate-+r+98.8%
metadata-eval98.8%
mul-1-neg98.8%
unsub-neg98.8%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.2e+121)
(* x y)
(if (<= x -2.8e+50)
(* x z)
(if (<= x -1.3e-15) (* x y) (if (<= x 1.65e-12) (- z) (* x y))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.2e+121) {
tmp = x * y;
} else if (x <= -2.8e+50) {
tmp = x * z;
} else if (x <= -1.3e-15) {
tmp = x * y;
} else if (x <= 1.65e-12) {
tmp = -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.2d+121)) then
tmp = x * y
else if (x <= (-2.8d+50)) then
tmp = x * z
else if (x <= (-1.3d-15)) then
tmp = x * y
else if (x <= 1.65d-12) then
tmp = -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.2e+121) {
tmp = x * y;
} else if (x <= -2.8e+50) {
tmp = x * z;
} else if (x <= -1.3e-15) {
tmp = x * y;
} else if (x <= 1.65e-12) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.2e+121: tmp = x * y elif x <= -2.8e+50: tmp = x * z elif x <= -1.3e-15: tmp = x * y elif x <= 1.65e-12: tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.2e+121) tmp = Float64(x * y); elseif (x <= -2.8e+50) tmp = Float64(x * z); elseif (x <= -1.3e-15) tmp = Float64(x * y); elseif (x <= 1.65e-12) tmp = Float64(-z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.2e+121) tmp = x * y; elseif (x <= -2.8e+50) tmp = x * z; elseif (x <= -1.3e-15) tmp = x * y; elseif (x <= 1.65e-12) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.2e+121], N[(x * y), $MachinePrecision], If[LessEqual[x, -2.8e+50], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.3e-15], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.65e-12], (-z), N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{+121}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -2.8 \cdot 10^{+50}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.3 \cdot 10^{-15}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.65 \cdot 10^{-12}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.2e121 or -2.7999999999999998e50 < x < -1.30000000000000002e-15 or 1.65e-12 < x Initial program 97.4%
Taylor expanded in y around inf 61.4%
if -1.2e121 < x < -2.7999999999999998e50Initial program 100.0%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 72.5%
if -1.30000000000000002e-15 < x < 1.65e-12Initial program 100.0%
Taylor expanded in x around 0 79.4%
neg-mul-179.4%
Simplified79.4%
Final simplification70.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -7e-21) (not (<= x 4.8e-12))) (* x (+ y z)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7e-21) || !(x <= 4.8e-12)) {
tmp = x * (y + z);
} else {
tmp = -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 <= (-7d-21)) .or. (.not. (x <= 4.8d-12))) then
tmp = x * (y + z)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7e-21) || !(x <= 4.8e-12)) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7e-21) or not (x <= 4.8e-12): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7e-21) || !(x <= 4.8e-12)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7e-21) || ~((x <= 4.8e-12))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7e-21], N[Not[LessEqual[x, 4.8e-12]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{-21} \lor \neg \left(x \leq 4.8 \cdot 10^{-12}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -7.0000000000000007e-21 or 4.79999999999999974e-12 < x Initial program 97.7%
Taylor expanded in x around inf 97.4%
+-commutative97.4%
Simplified97.4%
if -7.0000000000000007e-21 < x < 4.79999999999999974e-12Initial program 100.0%
Taylor expanded in x around 0 79.4%
neg-mul-179.4%
Simplified79.4%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -3750.0) (not (<= x 0.052))) (* x (+ y z)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3750.0) || !(x <= 0.052)) {
tmp = x * (y + z);
} else {
tmp = z * (x + -1.0);
}
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 <= (-3750.0d0)) .or. (.not. (x <= 0.052d0))) then
tmp = x * (y + z)
else
tmp = z * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3750.0) || !(x <= 0.052)) {
tmp = x * (y + z);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3750.0) or not (x <= 0.052): tmp = x * (y + z) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3750.0) || !(x <= 0.052)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3750.0) || ~((x <= 0.052))) tmp = x * (y + z); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3750.0], N[Not[LessEqual[x, 0.052]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3750 \lor \neg \left(x \leq 0.052\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -3750 or 0.0519999999999999976 < x Initial program 97.6%
Taylor expanded in x around inf 99.0%
+-commutative99.0%
Simplified99.0%
if -3750 < x < 0.0519999999999999976Initial program 100.0%
Taylor expanded in y around 0 78.8%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (<= x -1.9e-17) (* x y) (if (<= x 9.2e-9) (- z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.9e-17) {
tmp = x * y;
} else if (x <= 9.2e-9) {
tmp = -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.9d-17)) then
tmp = x * y
else if (x <= 9.2d-9) then
tmp = -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.9e-17) {
tmp = x * y;
} else if (x <= 9.2e-9) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.9e-17: tmp = x * y elif x <= 9.2e-9: tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.9e-17) tmp = Float64(x * y); elseif (x <= 9.2e-9) tmp = Float64(-z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.9e-17) tmp = x * y; elseif (x <= 9.2e-9) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.9e-17], N[(x * y), $MachinePrecision], If[LessEqual[x, 9.2e-9], (-z), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{-17}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 9.2 \cdot 10^{-9}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.9000000000000001e-17 or 9.1999999999999997e-9 < x Initial program 97.7%
Taylor expanded in y around inf 57.9%
if -1.9000000000000001e-17 < x < 9.1999999999999997e-9Initial program 100.0%
Taylor expanded in x around 0 79.4%
neg-mul-179.4%
Simplified79.4%
Final simplification68.6%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 98.8%
Taylor expanded in x around 0 41.2%
neg-mul-141.2%
Simplified41.2%
Final simplification41.2%
herbie shell --seed 2023257
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))