
(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 5 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 (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + 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 = (x * (z + y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 98.0%
*-commutative98.0%
distribute-rgt-out--98.0%
cancel-sign-sub-inv98.0%
metadata-eval98.0%
neg-mul-198.0%
associate-+r+98.0%
unsub-neg98.0%
+-commutative98.0%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -3.8e-178) (not (<= y 2.2e-127))) (- (* x y) z) (- (* x z) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.8e-178) || !(y <= 2.2e-127)) {
tmp = (x * y) - z;
} else {
tmp = (x * z) - 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 <= (-3.8d-178)) .or. (.not. (y <= 2.2d-127))) then
tmp = (x * y) - z
else
tmp = (x * z) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3.8e-178) || !(y <= 2.2e-127)) {
tmp = (x * y) - z;
} else {
tmp = (x * z) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.8e-178) or not (y <= 2.2e-127): tmp = (x * y) - z else: tmp = (x * z) - z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.8e-178) || !(y <= 2.2e-127)) tmp = Float64(Float64(x * y) - z); else tmp = Float64(Float64(x * z) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.8e-178) || ~((y <= 2.2e-127))) tmp = (x * y) - z; else tmp = (x * z) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.8e-178], N[Not[LessEqual[y, 2.2e-127]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{-178} \lor \neg \left(y \leq 2.2 \cdot 10^{-127}\right):\\
\;\;\;\;x \cdot y - z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z - z\\
\end{array}
\end{array}
if y < -3.80000000000000015e-178 or 2.2000000000000001e-127 < y Initial program 97.4%
*-commutative97.4%
distribute-rgt-out--97.4%
cancel-sign-sub-inv97.4%
metadata-eval97.4%
neg-mul-197.4%
associate-+r+97.4%
unsub-neg97.4%
+-commutative97.4%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 85.9%
if -3.80000000000000015e-178 < y < 2.2000000000000001e-127Initial program 100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
cancel-sign-sub-inv100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 94.1%
Final simplification88.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.65e+32) (not (<= x 6.5e-5))) (* x z) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.65e+32) || !(x <= 6.5e-5)) {
tmp = x * 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 <= (-1.65d+32)) .or. (.not. (x <= 6.5d-5))) then
tmp = x * z
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.65e+32) || !(x <= 6.5e-5)) {
tmp = x * z;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.65e+32) or not (x <= 6.5e-5): tmp = x * z else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.65e+32) || !(x <= 6.5e-5)) tmp = Float64(x * z); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.65e+32) || ~((x <= 6.5e-5))) tmp = x * z; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.65e+32], N[Not[LessEqual[x, 6.5e-5]], $MachinePrecision]], N[(x * z), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{+32} \lor \neg \left(x \leq 6.5 \cdot 10^{-5}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.6500000000000001e32 or 6.49999999999999943e-5 < x Initial program 95.5%
*-commutative95.5%
distribute-rgt-out--95.5%
cancel-sign-sub-inv95.5%
metadata-eval95.5%
neg-mul-195.5%
associate-+r+95.5%
unsub-neg95.5%
+-commutative95.5%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around inf 53.2%
Taylor expanded in x around inf 53.1%
*-commutative53.1%
Simplified53.1%
if -1.6500000000000001e32 < x < 6.49999999999999943e-5Initial program 100.0%
fma-define100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 68.8%
mul-1-neg68.8%
Simplified68.8%
Final simplification62.0%
(FPCore (x y z) :precision binary64 (- (* x y) z))
double code(double x, double y, double z) {
return (x * 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 = (x * y) - z
end function
public static double code(double x, double y, double z) {
return (x * y) - z;
}
def code(x, y, z): return (x * y) - z
function code(x, y, z) return Float64(Float64(x * y) - z) end
function tmp = code(x, y, z) tmp = (x * y) - z; end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y - z
\end{array}
Initial program 98.0%
*-commutative98.0%
distribute-rgt-out--98.0%
cancel-sign-sub-inv98.0%
metadata-eval98.0%
neg-mul-198.0%
associate-+r+98.0%
unsub-neg98.0%
+-commutative98.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 79.1%
(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.0%
fma-define99.6%
sub-neg99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in x around 0 40.2%
mul-1-neg40.2%
Simplified40.2%
herbie shell --seed 2024107
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))