
(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.0%
*-commutative98.0%
sub-neg98.0%
distribute-rgt-in98.0%
associate-+r+98.0%
metadata-eval98.0%
mul-1-neg98.0%
unsub-neg98.0%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.09e+189)
(* x z)
(if (<= x -1.45e-61)
(* x y)
(if (<= x 6e-41)
(- z)
(if (<= x 1.12e+66) (* x y) (if (<= x 7.7e+230) (* x z) (* x y)))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.09e+189) {
tmp = x * z;
} else if (x <= -1.45e-61) {
tmp = x * y;
} else if (x <= 6e-41) {
tmp = -z;
} else if (x <= 1.12e+66) {
tmp = x * y;
} else if (x <= 7.7e+230) {
tmp = x * 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.09d+189)) then
tmp = x * z
else if (x <= (-1.45d-61)) then
tmp = x * y
else if (x <= 6d-41) then
tmp = -z
else if (x <= 1.12d+66) then
tmp = x * y
else if (x <= 7.7d+230) then
tmp = x * 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.09e+189) {
tmp = x * z;
} else if (x <= -1.45e-61) {
tmp = x * y;
} else if (x <= 6e-41) {
tmp = -z;
} else if (x <= 1.12e+66) {
tmp = x * y;
} else if (x <= 7.7e+230) {
tmp = x * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.09e+189: tmp = x * z elif x <= -1.45e-61: tmp = x * y elif x <= 6e-41: tmp = -z elif x <= 1.12e+66: tmp = x * y elif x <= 7.7e+230: tmp = x * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.09e+189) tmp = Float64(x * z); elseif (x <= -1.45e-61) tmp = Float64(x * y); elseif (x <= 6e-41) tmp = Float64(-z); elseif (x <= 1.12e+66) tmp = Float64(x * y); elseif (x <= 7.7e+230) tmp = Float64(x * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.09e+189) tmp = x * z; elseif (x <= -1.45e-61) tmp = x * y; elseif (x <= 6e-41) tmp = -z; elseif (x <= 1.12e+66) tmp = x * y; elseif (x <= 7.7e+230) tmp = x * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.09e+189], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.45e-61], N[(x * y), $MachinePrecision], If[LessEqual[x, 6e-41], (-z), If[LessEqual[x, 1.12e+66], N[(x * y), $MachinePrecision], If[LessEqual[x, 7.7e+230], N[(x * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.09 \cdot 10^{+189}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.45 \cdot 10^{-61}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 6 \cdot 10^{-41}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 1.12 \cdot 10^{+66}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 7.7 \cdot 10^{+230}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.09000000000000001e189 or 1.12e66 < x < 7.6999999999999999e230Initial program 93.9%
*-commutative93.9%
sub-neg93.9%
distribute-rgt-in93.9%
associate-+r+93.9%
metadata-eval93.9%
mul-1-neg93.9%
unsub-neg93.9%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 63.2%
Taylor expanded in x around inf 63.2%
if -1.09000000000000001e189 < x < -1.45e-61 or 5.99999999999999978e-41 < x < 1.12e66 or 7.6999999999999999e230 < x Initial program 98.9%
Taylor expanded in y around inf 61.6%
if -1.45e-61 < x < 5.99999999999999978e-41Initial program 100.0%
Taylor expanded in x around 0 84.4%
neg-mul-184.4%
Simplified84.4%
Final simplification70.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.45e-61) (not (<= x 4.4e-41))) (* x (+ y z)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.45e-61) || !(x <= 4.4e-41)) {
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 <= (-1.45d-61)) .or. (.not. (x <= 4.4d-41))) 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 <= -1.45e-61) || !(x <= 4.4e-41)) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.45e-61) or not (x <= 4.4e-41): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.45e-61) || !(x <= 4.4e-41)) 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 <= -1.45e-61) || ~((x <= 4.4e-41))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.45e-61], N[Not[LessEqual[x, 4.4e-41]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{-61} \lor \neg \left(x \leq 4.4 \cdot 10^{-41}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.45e-61 or 4.4e-41 < x Initial program 96.8%
Taylor expanded in x around inf 92.6%
+-commutative92.6%
Simplified92.6%
if -1.45e-61 < x < 4.4e-41Initial program 100.0%
Taylor expanded in x around 0 84.4%
neg-mul-184.4%
Simplified84.4%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -14500.0) (not (<= x 8.3e-41))) (* x (+ y z)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -14500.0) || !(x <= 8.3e-41)) {
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 <= (-14500.0d0)) .or. (.not. (x <= 8.3d-41))) 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 <= -14500.0) || !(x <= 8.3e-41)) {
tmp = x * (y + z);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -14500.0) or not (x <= 8.3e-41): tmp = x * (y + z) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -14500.0) || !(x <= 8.3e-41)) 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 <= -14500.0) || ~((x <= 8.3e-41))) tmp = x * (y + z); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -14500.0], N[Not[LessEqual[x, 8.3e-41]], $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 -14500 \lor \neg \left(x \leq 8.3 \cdot 10^{-41}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -14500 or 8.3000000000000004e-41 < x Initial program 96.6%
Taylor expanded in x around inf 96.3%
+-commutative96.3%
Simplified96.3%
if -14500 < x < 8.3000000000000004e-41Initial program 100.0%
Taylor expanded in y around 0 81.0%
Final simplification89.7%
(FPCore (x y z) :precision binary64 (if (<= x -1.45e-61) (* x y) (if (<= x 3e-41) (- z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.45e-61) {
tmp = x * y;
} else if (x <= 3e-41) {
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.45d-61)) then
tmp = x * y
else if (x <= 3d-41) 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.45e-61) {
tmp = x * y;
} else if (x <= 3e-41) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.45e-61: tmp = x * y elif x <= 3e-41: tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.45e-61) tmp = Float64(x * y); elseif (x <= 3e-41) 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.45e-61) tmp = x * y; elseif (x <= 3e-41) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.45e-61], N[(x * y), $MachinePrecision], If[LessEqual[x, 3e-41], (-z), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{-61}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 3 \cdot 10^{-41}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.45e-61 or 2.99999999999999989e-41 < x Initial program 96.8%
Taylor expanded in y around inf 54.1%
if -1.45e-61 < x < 2.99999999999999989e-41Initial program 100.0%
Taylor expanded in x around 0 84.4%
neg-mul-184.4%
Simplified84.4%
Final simplification65.7%
(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%
Taylor expanded in x around 0 37.2%
neg-mul-137.2%
Simplified37.2%
Final simplification37.2%
herbie shell --seed 2023223
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))